Queries
SOQL FROM
Specifying Objects
SOQL FROM identifies the Salesforce object to query like Contact.
Introduction to SOQL FROM Clause
The SOQL FROM clause is used to specify the Salesforce object you want to query. It's an essential part of any SOQL query, as it defines the dataset from which you will retrieve records. In Salesforce, objects can be standard, such as Account
or Contact
, or custom, such as CustomObject__c
.
Basic Syntax of the FROM Clause
The basic syntax for using the FROM clause in a SOQL query is as follows:
Here, ObjectName
is the name of the Salesforce object you're querying, and field1
, field2
, etc., are the fields you want to retrieve from that object.
Querying Standard Salesforce Objects
To query a standard Salesforce object, simply use the object's name in the FROM clause. Here's an example of querying the Contact
object:
This query retrieves the first name, last name, and email of each contact in the Contact
object.
Querying Custom Salesforce Objects
Custom objects in Salesforce have unique names that end with __c
. To query a custom object, include the custom object name in the FROM clause. For example:
This query retrieves the custom fields CustomField1__c
and CustomField2__c
from the CustomObject__c
object.
Best Practices for Using the FROM Clause
- Use Descriptive Object Names: Ensure that the object names in your queries are clear and descriptive to improve readability.
- Limit Fields: Only select the fields you need to reduce processing time and resource usage.
- Use Indexes: Where possible, make use of indexed fields to speed up query execution.