Build Record Map from Lookup
Takes a collection of records as input
and the name of a lookup field specified as lookupField
. This will then query for all the related records of the object specified by the lookupField
. The fields loaded for the related records are defined by selectFields
. This provides an efficient way to query for a large number of related records at once.
To use the RecordMap later in your Flow, make sure to select Store Output Variables
and assign it to a variable resource with a data type of Apex-Defined
and an apex class of GradientWorks__RecordMap
. When creating the resource, do not check "Allow multiple values (collection)".
For example, consider the following Flow structure:
Use
Get Records
to retrieve a collection of ContactsUse a
Loop
over the collection of ContactsUse
Get Records
inside the loop to retrieve the Account related to each Contact usingContact.AccountId
This works, but performs an additional SOQL query for each Contact. If you have 50 Contacts, your Flow will perform 51 queries. One to get the original Contact list and then one per Contact. You will rapidly hit Salesforce governor limits and your Flow may run slowly.
This action allows for a pattern like so:
Use
Get Records
to retrieve a collection of ContactsUse Build Record Map from Lookup with the Contacts as
input
to get a RecordMap of related Accounts usingAccountId
as thelookupField
and store the RecordMap to an output variable.Use a
Loop
over the collection of ContactsUse Get Record from Record Map inside the loop with
Contact.AccountId
as the key to get the related Account
While this requires an extra step, it only uses 2 SOQL queries: one to get the list of contacts and one to retrieve all the related accounts. Your flow will be much less likely to hit governor limits and will run more quickly.
Inputs
input
Yes
List<SObject>
A collection of input records with lookup fields
lookupField
Yes
String
selectFields
Yes
String
A comma-delimited list of fields on the related object you want to include. e.g. Id, Name, CustomField__c
. You must specify at least one field.
Outputs
recordMap
Last updated