Posted on April 27, 2017 2 Comments
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
Posted on January 16, 2013 1 Comment
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, […]
Posted on January 15, 2013 2 Comments
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 + […]
Posted on January 4, 2013 Leave a Comment
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 […]