Activity Forums Salesforce® Discussions Differentiate between Static SOQL and Dynamic SOQL in Salesforce.

  • Anurag

    Member
    September 20, 2018 at 6:50 am

    Hi Pavan,

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

    list<Contact> con=[Select Id, LastName from Contact]

    Dynamic SOQL refers to the creation of a SOQL string at runtime with Apex code. Dynamic SOQL enables you to create more flexible applications.To create dynamic query at runtime, we use Database.query() method.

    For example,

    String soql = 'SELECT id, name FROM Account';

    List<Account> accList = Database.query(soql);

    Thanks.

  • Aman

    Member
    September 29, 2018 at 4:43 pm

    Hi,

    Static SOQL is written in ([]) array brackets. Its good to use when you did not have dynamic chnages is SOQL.

    Dynamic SOQL refers to the creation of a SOQL string at run time with Apex code. Dynamic SOQL enables you to create more flexible applications. For example, you can create a search based on input from an end user or update records with varying field names.

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos