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

 

Install

Version 0.1

 

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
List of Ids 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.
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 Collection of values to search Must be this type
– Allow multiple must be checked.
Search Scope

The scope of the SOSL search (default ALL FIELDS)

see more.

ALL FIELDS
     
outputCollection The records being returned Create a record variable-Allow multiple must be checked.

 

 

Acknowledgements