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

    Top 8 Salesforce Integrations for Small and Medium-Sized Businesses

    Blog in Salesforce integration

    At Cloud Analogy, we understand the importance of efficient business processes for Small and Medium-sized Businesses (SMBs). Salesforce, a leading Customer Relationship Management (CRM) platform,…

    Applications, Automate, Bug Reporting, Business Processes, Cloud Analogy
    Chris Aug 17, 2023
    1,576  Views
    Messaging in Salesforce

    Messaging in Salesforce: Ways To Send Text, WhatsApp, Viber Messages

    Blog in AppExchange, Salesforce

    The restrictions during the COVID-19 quarantine boosted the growth of digital communication. Instead of interacting face-to-face, vendors are now reaching customers through messages and emails.…

    App Components, Automate Messaging, Business Needs, Campaign Members, Chatbot Conversations
    Brimit Oct 27, 2022
    3,272  Views

    Fetching and Displaying Data in Salesforce Lightning Web Components: A Step-by-Step Guide Salesforce

    Blog in Salesforce

    Salesforce Lightning Web Components (LWC) is a framework provided by Salesforce to develop web applications easily. You know how to build cool things with building…

    builder, Building Blocks, Cacheable, Component, Data Display
    Nayan Sep 27, 2023
    2,290  Views

    Popular Salesforce Videos

    How Salesforce Industries can Help Organizations to Save Millions?

    How Salesforce Industries can Help Organizations to Save Millions?

    Video in Salesforce Stories

    Salesforce Industries i.e Vlocity empowers businesses with powerful platforms to boost collaboration and makes it easy to deliver great customer experiences. It provides tailored solutions…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Learning, Business
    Cyntexa Dec 8, 2022
    1,362  Views
    My Wild Career Journey: From Lawyer to Salesforce Consultant

    My Wild Career Journey: From Lawyer to Salesforce Consultant

    Video in Salesforce Stories

    People often ask Brainiate what his career journey looked like, and in this video he share with you the key milestones that brought him to…

    Salesforce Training, Salesforce Jobs, Salesforce Consultant, Salesforce Ecosystem, Salesforce Video
    Rupal Kakkar Aug 26, 2021
    2,512  Views
    Welcome to the Partner Marketing Center | Salesforce

    Welcome to the Partner Marketing Center | Salesforce

    Video in Salesforce Products, Marketing

    The Partner Marketing Center (PMC) is your one-stop shop for customizable marketing assets. By logging into the PMC you can easily access, customize, and deploy…

    Salesforce Training, Salesforce Tutorial, Salesforce Partner, salesforce, Salesforce Video
    Pooja Apr 21, 2021
    2,332  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.