SOQL Syntax and Explanation

SOQL Syntax : In our previous salesforce tutorial we have learned about What is SOQL. In this Salesforce Training tutorial we are going to learn about example of SOQL Syntax and its explanation.

SOQL Syntax

Salesforce Object Query Language uses SELECT keyword to fetch data from Objects and fields. In Structures Query language (SQL) the keyword SELECT is used to fetch data.

SOQL Syntax :

SELECT fields
FROM object
WHERE condition
ordering LIMIT FOR VIEW Or FOR REFERENCE
OFFSET
UPDATE VIEWSTAT
 

From above syntax we have to know clearly about each term in the Syntax. Remember carefully stated below.

  • Fields : When we mention fields it uses API names of an Object.
  • Object : When we mention Object it denotes Custom and Standard Objects.
  • Condition : To filter records we use conditions in SOQL.
  • Ordering : This is used for Ordering the results. This may be optional in SOQL.
  • Limit : It Limits the number of records when fetching.
  • FOR VIEW :  This is used to fetch records from last day fetched records.
  • FOR REFERENCE : To update LastReferencedDate this is used.
  • OFFSET : To denote the starting row of the record this is used.
  • UPDATE VIEWSTAT : This updates the articles view statistics for fetched records.

When writing SOQL statements we use API names for fields and labels of the fields should not be used.

Standard Objects : Field Name refers as API name.

Custom Objects : API name column refers to API name.

How to get API names for Standard Objects ?

In this example we are going to get API name for Standard Object called “Account”. Follow the steps as shown below.

Go to Build=>Customize=>Accounts=>Fields.

SOQL Syntax and Explanation

SOQL Syntax and Explanation

In Standard Object Field name as referred as API name  as shown below.

SOQL Syntax and Explanation

SOQL Syntax and Explanation

How to get API names for Custom Objects ?

To know API names for Custom objects in salesforce go to Build=>Create=>Objects.

SOQL Syntax and Explanation

select any custom object .

SOQL Syntax and ExplanationNow go to Custom Fields & Relationships.

SOQL Syntax and Explanation

The  API names of the fields are as shown above.

 

0 comments… add one

Leave a Comment

error: Content is protected !!