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

FieldApiINames – to returnComma-separated list of field API names.ID,Name,Primary_contact__c
Where ClauseA 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 NameThe name of the ObjectAccount
4. a) List of Ids to Limit Get toYou 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 onSpecify which field to include in the IN statement aboveDefaults to Id
Bypass SharingWe 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 QueriesComma 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 Objectseg. Account,Opportunity,Case,Lead,User  
Max Number of recordsLimit 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