Salesforce Salesforce Object Query Language (SOQL) SOQL Query With Filtering


Example

SELECT Name FROM User WHERE IsActive = true

This will return the name of all active Users.

SELECT Name, Phone FROM Contact WHERE CreatedDate >= 2016-01-01T00:00:00.000Z

This will return Contacts created on or after January 1st, 2016.

SELECT Id, Name FROM Account LIMIT 100

This will return the first 100 Accounts from an unordered list.

SELECT Id, Name, Phone FROM Lead WHERE Phone LIKE '(%) %-%'

This will return Leads with a phone number matching the specified format. "%" acts as a wild card character.

Using LIKE '% %' also enables a developer to replicate a CONTAINS( ) formula.

SELECT Email FROM Lead WHERE LeadSource LIKE '%Google%'

Will return Leads with a lead source that contains Google i.e. 'Google AdWords' & 'Google Natural Search'.