Toggle Side Panel

  • Blogs
  • 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
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Blogs
    • 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
    • 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 8 years, 9 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

    Popular Salesforce Blogs

    Customizing Your Salesforce Login Process with My Domain

    How to Customize Your Salesforce Login Process with My Domain?

    Blog in Salesforce customization

    My domain : My domain is a salesforce identity feature that let you personalize your salesforce org by customizing your login URL. Reasons to register…

    Domain Management in Salesforce, Login Flows, My Domain, Salesforce Customization, Salesforce Login
    Aman Apr 24, 2018
    5,147  Views

    Omni-сhannel in Salesforce: Setting the Standard for Customer Service

    Blog in Salesforce customization

    Modern consumers demand convenience, connecting with companies from anywhere using smartphones or laptops. The true advantage emerges when customers have multiple options tailored to their…

    Einstein AI, Einstein Analytics, Einstein Bot, Einstein Discovery, Multichannel
    Twistellar Feb 21, 2024
    2,489  Views
    Awesome Admin

    Salesforce Awesome Admin Tips for Productivity | Salesforce Admin

    Blog in Salesforce Admin

    It’s no secret that Salesforce continually ranks as one of the highest recommended cloud-based software management platforms. It has proven to be an incredibly robust…

    App, Awesome Admin, Boost Productivity, Cloud-based Software Management Platforms, Collaboration
    Access Global Jun 17, 2022
    2,252  Views

    Popular Salesforce Videos

    Salesforce DMP – Capture, Unify and Activate Your Data

    Salesforce DMP – Capture, Unify and Activate Your Data

    Video in Others

    Learn how the Salesforce DMP allows marketers to capture, unify and activate their data enabling them to deliver more relevant and personalized experiences to their…

    Salesforce Products, Marketing Automation, Salesforce Data Management, Salesforce Data, Customer Success
    Deepti Jun 27, 2018
    2,254  Views
    How To Land A Salesforce Job In India

    How To Land A Salesforce Job In India

    Video in Others, Salesforce Stories, Salesforce Training

    This video explained about to land a Salesforce job in India. This is a great opportunity to enter the Salesforce echo systems for non-Salesforce professionals…

    Salesforce Developer, Covid19, Salesforce Job, Land a Salesforce Job in India, Salesforce Echo Systems
    Rupal Kakkar Sep 11, 2020
    2,037  Views
    What are sObjects in Salesforce? | Salesforce Development Tutorials

    What are sObjects in Salesforce? | Salesforce Development Tutorials

    Video in Salesforce Training

    In this video Shrey not only teaches you sObjects but also demonstrates the use of sObjects in Apex. He explained about the sObjects and how…

    Salesforce Training, Salesforce Development, Salesforce Apex, Salesforce Tutorials, Salesforce Video
    Prafull Aug 6, 2021
    1,742  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®.

    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.