Toggle Side Panel

  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
      • Marketing Cloud ConsultantsMarketing Cloud Consultants
      • Service Cloud ConsultantsService Cloud Consultants
      • Experience Cloud ConsultantsExperience Cloud Consultants
      • Analytics Cloud ConsultantsAnalytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
      • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
      • Health Cloud ConsultantsHealth Cloud Consultants
      • Commerce Cloud ConsultantsCommerce Cloud Consultants
      • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
    • Salesforce Experts by Location
      • USATop Salesforce Consultants in USA
      • IndiaTop Salesforce Consultants in India
      • AustraliaTop Salesforce Consultants in Australia
      • United KingdomTop Salesforce Consultants in UK
      • CanadaTop Salesforce Consultants in Canada
  • Webinars
  • Marketplace
  • Advertise With Us
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
        • Marketing Cloud ConsultantsMarketing Cloud Consultants
        • Service Cloud ConsultantsService Cloud Consultants
        • Experience Cloud ConsultantsExperience Cloud Consultants
        • Analytics Cloud ConsultantsAnalytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
        • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
        • Health Cloud ConsultantsHealth Cloud Consultants
        • Commerce Cloud ConsultantsCommerce Cloud Consultants
        • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
      • Salesforce Experts by Location
        • USATop Salesforce Consultants in USA
        • IndiaTop Salesforce Consultants in India
        • AustraliaTop Salesforce Consultants in Australia
        • United KingdomTop Salesforce Consultants in UK
        • CanadaTop Salesforce Consultants in Canada
    • Webinars
    • Marketplace
    • Advertise With Us
    • Contact Us
    • Discussions
    Close search

    Activity › Forums › Salesforce® Discussions › What is Dynamic SOQL in Salesforce? How is it different from Normal Static SOQL?

    Tagged: Account List, Database Query, Dynamic SOQL, EscapeSingleQuotes, Normal SOQL, Salesforce Contacts, Salesforce Fields, Salesforce SOQL, SOQL, SOQL Injection, SOQL Query

    • Salesforce® Discussions

      What is Dynamic SOQL in Salesforce? How is it different from Normal Static SOQL?

      Posted by Ankit on January 30, 2018 at 12:49 PM

      What is Dynamic SOQL in Salesforce? How is it different from Normal Static SOQL?

      Manpreet replied 7 years, 12 months ago 2 Members · 1 Reply
      • Account List
      • Database Query
      • Dynamic SOQL
      • EscapeSingleQuotes
      • Normal SOQL
      • Salesforce Contacts
      • Salesforce Fields
      • Salesforce SOQL
      • SOQL
      • SOQL Injection
      • SOQL Query
    • 1 Reply
    • Manpreet

      Member
      January 30, 2018 at 2:49 PM

      Hi Ankit,

      Static SOQL is one which you write in square brackets. It is good to use when you didn't have any dynamic changes in the SOQL query.

      For e.g when the fields names or where conditions is needed to be defined dynamically we didn't use static SOQL. Then we need to use dynamic SOQL.

      ________________________________________________________________________________

      DYNAMIC SOQL :

      public Boolean DynamicSOQL(string user_id, string yourField) {
      String query = 'SELECT ' + yourField + ' FROM Contact WHERE Id = ' + user_id;
      Contact[] myContacts = Database.query(query);

      if(myContacts.size() < 1){
      return false;
      }
      else{
      myContacts[0].put(yourField,false);
      Database.update(myContacts[0]);
      return true;
      }
      }

      STATIC SOQL:

      List<Contact> conList = [SELECT Id, LastName From Contact];

      ________________________________________________________________________________

      One DISADVANTAGE with DYNAMIC SOQL is it causes SOQL injection in where condition which fetching on the basis of some text. To avoid which we need to use String.escapeSingleQuotes. There is no possibility of these in STATIC SOQL.

      Thanks.

    Log In to reply.

    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me

    application solution

    Popular Salesforce Blogs

    AWS Cloud Basics

    AWS Cloud Basics | Salesforce Trailhead Guide

    Blog in Salesforce

    In this blog, we will be taking a look at the topic of AWS Cloud. As we all know Cloud computing is the on-demand provision…

    Application, Artificial Intelligence, AWS, AWS Cloud, AWS Cloud Basics
    bhawana Nov 11, 2022
    2,565  Views
    Named Credentials

    Integration Using Named Credentials | Salesforce Developer Guide

    Blog in Salesforce Training

    The Following are the Benefits of Using Named Credentials: A Named credential specifies the end URL of the callout and its verification parameters required in…

    Authentication Protocol, Authentication Protocols, Callback URL, Callout Description, Connected Apps
    rajesh andani May 4, 2022
    7,063  Views

    Salesforce Consulting Services - 8 Excellent Salesforce Tools to improve your Sales Pipeline

    Blog in Salesforce, Salesforce Consultant

    Ever asked any sales organization which technology they have heavily invested as an alternative to the CRM? The answer is Salesforce which has now become…

    Business, Business Operations, Cloud CRM Platform, Content Management Tool, Hubspot
    Emorphis Apr 29, 2020
    2,742  Views

    Popular Salesforce Videos

    How To Use Javascript Editor In Formstack Part 2 - Learn Salesforce Series By Algoworks

    How To Use Javascript Editor In Formstack Part 2 - Learn Salesforce Series By Algoworks

    Video in Salesforce Integration, Salesforce Training

    Learn how to integrate Javascript editor in Formstack in this Salesforce tutorial brought to you by Algoworks. Did you miss the complete tutorial? To watch…

    Salesforce Training, Salesforce Integration, salesforce, salesforce services, Salesforce Video
    Algoworks Aug 28, 2020
    2,087  Views
    Creating an Approval Process in Salesforce with Example

    Creating an Approval Process in Salesforce with Example

    Video in Salesforce Implementation

    Approval Process in Salesforce is an automated process that automates how Salesforce records are approved in your org. Approval Process in Salesforce is a combination…

    Salesforce Administration, Salesforce1, Salesforce Records, Email Templates, Salesforce Fields
    Pooja Apr 3, 2018
    3,223  Views
    What is Field Dependency in Salesforce and When to use it?

    What is Field Dependency in Salesforce and When to use it?

    Video in Salesforce Implementation

    This video gives a complete knowledge of what Field Dependency is in Salesforce. It's divided this topic into 4 major points that are: 1. What…

    Salesforce Tutorial, Salesforce Beginner Tutorial, Salesforce Field Objects, Salesforce Fields, Field Dependency In Salesforce
    Prafull Feb 7, 2018
    2,164  Views
    Footer Forcetalks logo

    support@forcetalks.com

    • twitterx

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2023

    Top Salesforce® Bloggers 2023

    Top Salesforce Consultants

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    InsightHub

    Salesforce Blogs

    Salesforce Videos

    Salesforce Groups

    Salesforce Jobs

    © 2026 - Forcetalks ● All Rights Reserved

    Salesforce® is a trademark of Salesforce® Inc. No claim is made to the exclusive right to use “Salesforce”. Any services offered within the Forcetalks website/app are not sponsored or endorsed by Salesforce®.

    Try AuditMyCRM - It is a Salesforce CRM Audit tool which comprehensively scans your Salesforce org and gives you the list of errors or warnings you need to take care of.
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.