Archives

Query Multi-Select Picklists in SOQL

Create list of values to check for multi picklist Query using INCLUDES and using String.join to create string of List. Use , for OR and ; for AND to match values in picklist

Rate this:

Read More

SOQL self-join semi-join anti-join examples

Query Account from Contact using child-to-parent relationships: Select id, Name, Account.Name, Account.Owner.Name, Account.Owner.Profile.Name, RecordType.Name from Contact Sub Querying from Contact using parent-to-child relationships: Select id, Name, Account.Name, Account.Owner.Name, Account.Owner.Profile.Name, RecordType.Name, (Select Opportunity.Name, Opportunity.StageName from Contact.OpportunityContactRoles), (Select id from Contact.Tasks), (Select Id from Contact.Cases), (Select Id from Contact.OpenActivities) from Contact Outer Joins from Contact: Select id, […]

Rate this:

Read More

Static and dynamic SOQL queries and best practices

If you are building Dynamic SOQL Queries that can be using for Apex Classes and Batch Apex you can use the Database.query(”) function to build the query: private static final String soqlQuery = ‘Select id, OwnerId from Account’; public void updateAccountOwnerByOwnerName(String currentOwnerName, String newOwnerName) { Map<Account> updateAccountWithNewOwnerName = new Map(); List<Account> accountsAssignedToCurrentOwner = Database.query(soqlQuery + […]

Rate this:

Read More

Query SObject without burning SOQL queries

When you are writing Apex code you want to minimize the amount of SOQL queries in your code. One of the ways todo this is to create an SObject with some information of that object. Let us say you have the following SOQL query: Contact getAccountId = [Select AccountId from Contact limit 1]; Now you […]

Rate this:

Read More