Flow Action – Get/Search with APEX

What does it do?

It allows you to run a SOQL or SOSL query to retrieve a collection of records. This means you can select records using powerful and robust SOQL queries, or leverage the same search Salesforce offers in the Omnisearch bar, complete with fuzzy logic and incomplete words.

It can:

  • Work with any object
  • Get records without sharing. eg. moving a community user to an account they don’t yet have access to
  • Use IN statements – If you provide a list of Ids
  • Use Salesforce’s powerful search language to search all fields (with phonetic matching)
  • Stop using multiple get statements to find things
  • Advance where statements. Use OR logic in gets


Version 0.2


How to use

1/ Add an “action” to your flow and search for “Get/Search with APEX”

2/ Select the object name

3/ Add in the fields to find and the rest of the input fields

4/ Define a collection variable for the record output

5/ Then loop through each record and do as you like

Add Search queries

If you’re using a search query, you’ll need to add them to a list. This is done by setting up a text type collection variable and then using an assignment. Remember that this will do a search across most fields and you don’t need to tell it which field to look in.

Field Definitions

Input Description Example
FieldApiINames – to return Comma-separated list of field API names. ID,Name,Primary_contact__c
Where Clause A text value defining the where clause. You must not SOQL to add this.
You should be able to add nested statements and do fun advance things here like normal apex.
createddate = Last_N_Years:2
Object APi Name The name of the Object Account
4. a) List of Ids to Limit Get to You load a number of Ids into this variable and then it will return all of these.
This uses the Id IN :IdsList ability in Apex to find them all in one go.
Must be this type
– Allow multiple must be checked.
4. b) Which Id field to match list on Specify which field to include in the IN statement above Defaults to Id
Bypass Sharing We used this for checking for duplicate records before inserting. Or if you want to move a contact to an account that the user doesn’t have access yet. {!$GlobalConstant.True}
Search Queries Comma seperated list of values to search forCollection of values to search  
Search Scope

The scope of the SOSL search (default ALL FIELDS)

see more.

Search Extra Objects eg. Account,Opportunity,Case,Lead,User   
Max Number of records Limit to the total number of records to return. eg. 10   
SObject1.Record Collection  The records being returned  
2.Ids (String Collection) 

a list of Ids found/td>

3.Record Names (String Collection)  A list of names found  


You need to ensure that user’s profile has access to the following Apex Classes in order for the search component to work for them: AutoCompleteController, FlowFindCollection, FlowFindCollection_WithoutSharing