What is SOQL in Salesforce?

Jagdish Dhus
0

What is SOQL in Salesforce?

Ans-     a. SOQL stands for Salesforce Object Query Language.

             b. With the help of  SOQL you can fetch either one or more records from the object.

             c.  When you fetch the data with the help of SOQL then you can also add required user-defined conditions to filter the data.

Syntax of SOQL -

    SELECT <fieldname/api name> FROM objectname;

e.g.     
            SELECT Id, Name FROM Account;


Governor Limits of SOQL -

        a. We can have a max of 100 SOQL Queries.

        b. Each SOQL Query can return a max of 50,000 records. 


You can also add the conditions ( commonly called Clauses ) to the SOQL Query to filter the data.

  • SELECT Clause - This Clause is used to determine which fields to be displayed.
                e.g. -

                SELECT id, name, rating, industry, phone, fax FROM Account;

            This SELECT Clause contains a different number of optional sub-clauses.

                1. WHERE Clause - This Clause is used to add one or more user-defined conditions to the SOQL query. Based on your need you can also use the AND, OR operator.                      

                e.g. -
                         SELECT id, name FROM Contact WHERE FirstName='Guest' AND LastName='User'; 

                2. ORDER BY Clause - This Clause is used to re-arrange the result.

                    e.g. -   
                               SELECT Id, Name FROM Account ORDER BY Name DESC;

                 3. LIMIT Clause - This Clause is used to restrict the number of records to be get returned by SOQL Query.
                    e.g. -
                                SELECT id, name, rating, industry FROM Account LIMIT 2;

                  4. ALL ROWS Clause - This Clause is used to get all the records including Deleted Records.
                    e.g. - 
                                SELECT id, name, rating, industry FROM Account ALL ROWS;

                    5. FOR UPDATE Clause - This Clause is used to Lock the required records. Once use this clause then other users can not perform any operations.
                    e.g. - 
                                SELECT id, firstName. lastName, email, company FROM Lead FOR UPDATE;

                    6. LIKE Clause - This Clause is used to fetch similar types of records from the object.                                                          This clause is always used with WHERE Clause.
                    
        This Clause contains a number of expressions to fetch the data.

        a. WHERE Name LIKE ' A% ' ----  Name Starting with 'A' 

        b. WHERE Name LIKE ' %A ' ---- Name Ending with 'A' 

        c. WHERE Name LIKE ' _B% ' ----  Second Name Character is 'B'

        d. WHERE Name LIKE ' %A%% ' ---- Name Contains 'A' 

        e.g. -
                 SELECT id, name, rating, industry, annualrevenue FROM Account WHERE Name LIKE                                     'Guest%';


You Can Also Watch the Below Video of SOQL - 


 

Post a Comment

0Comments
Post a Comment (0)
To Top