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 8 years, 2 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

    show the required fields in picklist

    How to Show The Required Fields in Salesforce Picklist Dynamically?

    Blog in Data

    To show the require fields in Salesforce picklist you have to implement these codes in apex class. Apex class: public class objectController { public Map…

    Picklist, Picklist Field, Picklist Values, Related Fields, Salesforce Apex
    Rajan Mar 15, 2018
    2,387  Views
    financial service cloud

    5 Ways to Grow and Build Trust in Finance Business | Salesforce

    Blog in Others, Salesforce, Salesforce Cloud Platform

    We all know of the financial crisis in 2007. The one that sent shockwaves in the financial business, not only in the US but all…

    Artificial Intelligence, Banking, Consumer Behavior Patterns, CRM, Customer Acquisition
    AnavClouds Software Solutions Jul 16, 2020
    5,122  Views

    Salesforce Visualforce Vs Salesforce Lightning Component

    Blog in Others, Salesforce, Visualforce

    Visualforce On the server-side a strong set of tags solved in Visualforce. The visualforce framework is called a center page internet application type. Since the…

    Custom Controller, Helper Class, JavaScript, Lightning App Builder, Lightning Framework
    Aditya Feb 24, 2020
    5,466  Views

    Popular Salesforce Videos

    See the Future of APIs at Salesforce

    See the Future of APIs at Salesforce

    Video in Salesforce Apex, Salesforce Training

    Salesforce APIs are a way for other applications (or code in other applications) to programmatically access data within your Salesforce org, in a simple and…

    Salesforce Training, salesforce, Salesforce Applications, Salesforce Org, Salesforce Video
    Prafull Apr 7, 2021
    2,400  Views
    The Salesforce and Stripe Integration Solution

    The Salesforce and Stripe Integration Solution

    Video in Salesforce Integration

    Salesforce professionals choose us because we’re different. Our intuitive software connects Salesforce with Stripe and is simple to set up and configure and safe and…

    Salesforce Training, Salesforce Tutorial, Salesforce Integration, salesforce, Salesforce Video
    Algoworks Jul 28, 2021
    1,510  Views
    DreamTX Welcome Day 4: Skill Up with Trailhead | Dreamforce 2020 | Salesforce

    DreamTX Welcome Day 4: Skill Up with Trailhead | Dreamforce 2020 | Salesforce

    Video in Salesforce Stories, Events

    If you missed DreamTX DAY 4, then live this amazing experience here, we have covered it all for you. Learn about the latest innovation on…

    dreamforce, salesforce, Salesforce Event, Trailhead, Customer Success
    Pooja Dec 18, 2020
    2,138  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.