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, 10 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

    Salesforce & SharePoint Integration – A Combination To Enhance Business Processes

    Blog in Salesforce integration

    Salesforce SharePoint Integration – Salesforce is the world’s #1 cloud-based CRM giant offering comprehensive CRM solutions to millions of leading brands across the globe. However,…

    Chatter, CRM Solutions, Salesforce Chatter, Salesforce Integration, Salesforce Sharepoint integration
    DemandBlue Aug 22, 2019
    3,917  Views

    Apex Test Class in Salesforce - Lear All About It

    Blog in Salesforce Apex

    Introduction Apex testing framework enables you to write and execute tests for your apex classes and triggers on the lightning platform.  Apex unit tests ensure…

    Apex Rationale, Apex Test Class, Apex Test Class in Salesforce, Apex Testing Framework, Apex Unit Test
    NARENDRA Oct 17, 2022
    2,073  Views

    Populating Salesforce Data into a Table element

    Blog in Data

    Every product is investing huge effort in creating a nice user interface, making it “sexy” and inviting. There is no doubt that customers and service…

    Salesforce Data, Salesforce Data Insertion
    Ori Oct 24, 2017
    4,281  Views

    Popular Salesforce Videos

    Increase ROI by Investing in People | Make Earth Your Business

    Increase ROI by Investing in People | Make Earth Your Business

    Video in

    The video discusses the benefits of businesses that invest in and believe in their employees, customers, and communities. Investing in employee training and upskilling programs…

    salesforce, Customers, Employees, Productivity, Businesses
    Jogender Apr 18, 2023
    962  Views
    Creating a Roll-up Using DLRS | Salesforce Tutorial Video

    Creating a Roll-up Using DLRS | Salesforce Tutorial Video

    Video in Salesforce Admin

    In certain situations, an object does not support a roll-up or the relation is not permitted. Learn how to make it possible by using the…

    Salesforce Training, Salesforce Tutorial, Salesforce Video, Salesforce Learning, Salesforce Tutorial Video
    SkyPlanner Aug 12, 2021
    2,462  Views
    Get Started with Salesforce Order Management in Commerce Cloud

    Get Started with Salesforce Order Management in Commerce Cloud

    Video in Salesforce Cloud Platform

    This video will give you an overview of Salesforce Order Management and how to get started with implementing and using the application. In this session…

    Salesforce Training, Salesforce Tutorial, Salesforce Video, Salesforce Learning, Application
    Prafull Aug 19, 2022
    1,931  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

    © 2025 - 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.