Avoiding the 5 recipient limit on email action
A Warning in Advance
ViaSkipping limits is dumb, you probably shouldn't do it, but history is filled with people doing dumb stuff and getting away with it. What's the toolingworst api,that we'recould happen here? Maybe an email doesn't get sent, maybe your release manager vomits at the sight of your commit?
Problem Statement:
I want to send an email for notification from a flow, but I want to send it to more than 5 people from the standard email component.
In this example, I'm going to deleteset someup historica scheduled flow versions,to thischeck isfor superexpiring usefulpackage whenlicenses youand have reachednotify the shortadmin limit of 50. However, you can lose useful history that past you might have wanted to save.
Accessing the Tooling API
You can access the tooling APIteam, via the Salesforceapex Inspectorexception chomequeue. extension,(FYI there- the apex exception email recipients list can be set as the default notification for flow debug emails, which is aquite checkboxuseful atin smaller orgs)
Gather the topemail whichaddresses pointsinto youa atcollection:
Our first action is to collect the Toolingemail API:addresses from the Apex Email Notification table:
YouAnd can also accessadd the Toolingrecords APIto viaa thetext developercollection console:variable:
In this case, there are two possible locations for the email, as the notification emails can either hold an email address, or a lookup to a user, both can be added to the string collection.
Iterating our collection:
Our first action, once we have built our recipient collection, is to assign the count of records to a number variable. Then we can have a decision element to determine if we need to select only 5 recipients from the collection, or have fewer than five and can simply send the email.
Tooling API Developer Documentation
What versions could I remove?
SELECT Id, VersionNumber, Status, Description, MasterLabel, CreatedDate
FROM Flow
WHERE MasterLabel = 'Case Updates' AND Status != 'Active' ORDER BY CreatedDate ASC limit 19 Generally limit yourself to one flow at a time, for ease this example limits via the Masterlabel, as per the above image, you can see thatthe decision above, with the looping process handled by the more than 5 branch.
How to iterate:
The process for iterating here is simple step-wise, but not overly obvious when starting from a blank canvas. If we were doing this in the natural way (how you might describe it returnswithout bothplatform draftslimitations, beyond the 5 recipient limit)
-
- Take the first 5 out of the recipient collection
- Send them the email
- Back to the collection count element and
obseleteupdate
versions.
Step you1, dounfortunately, is not wantavailable in salesforce, we instead will have to removetake a few more steps:
-
- Duplicate your
currentcollectiondraftintowithachangestemporary collection - Sort your collection and limit to 5 using the Collection Sort element*
- Your temp collection now only has 5 recipients in
it!it, so send them the email - Remove those 5 recipients from your Original Collection
- Re-count the original collection and proceed to the decision
- Duplicate your
*Unlike the filter element, collection sort DOES modify the supplied collection, and DOES NOT accept resources as the limit variable. The modification is why we need to create a temporary collection for the 5 recipients in the loop.
DeletingStep versions1:
InDuplicate Salesforceyour Inspector,collection youinto cana simplytemporary copycollection:
Last5Recipients is an identially configured variable text collection that we will use to hold our current batch. Using the excelequals outputmeans that any current values in the collection should be overwritten each time.
Step 2:
Sort your collection and limit to 5 using the Collection Sort element:
This selects us the last 5 recipients in the collection, these will be the target for the next email action
Step 3:
Your temp collection now only has 5 recipients in it, so send them the email
Step 4:
Remove those 5 recipients from your Original Collection:
The remove all operator for the assignment element removes all occurences of the Value from the queryVariable in our case, we are then removing the 5 recipients that we have just emailed, from the original recipient collection.
Step 5:
Re-count the original collection and pasteproceed that intoto the uploaddecision:
The connect to element option allows you to connect to other parts of ayour dataflow, importsimply window:select your Assign Count of Recipients element (see here) and you've created your loop.
Notefinal thewarning: ToolingI APIhave checkboxNO atIDEA thehow top,far you could push this, I certainly wouldnt recommend building a huge notifiation list into this flow, there are better tools for mass emailing, and you're almost certian to have issues if using the above query, you willpush needthis toreally skip all the other column headers, as the delete operation expects a list of Id's.far.
ItIf doesn'tyou appearwere thatfeeling devparticularly consolecunning, canyou deletecould flowspackage unfortunately.this
an autolaunched flow, receiving a collection of recipients, a subject, and body, then call it asynchronously from across your org, saving you from having to rewrite it every time.







