I have been lately exploring on how to send bulk emails from flow. There is documented way to send single email using singleEmail action as described here. I implemented this and new I can successfully convert
Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
/*some awesome code*/
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {semail});
to
Map<String, Object> flowVariables = new Map<String, Object>{
'body' => htmlBody,
'toAddresses' => toAddresses,
\*some more keys as required by sendEmail action*\
};
Flow.Interview.SendEmail sendEmail = new Flow.Interview.SendEmail(params);
sendEmail.start();
However I wanted to send bulk emails i.e., I wanted to convert this
Messaging.SingleEmailMessage[] emails = new List<Messaging.SingleEmailMessage>();
for(/*some iteration*/){
Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
/*some awesome code*/
emails.add(semail );
}
Messaging.sendEmail(emails);
to
List<Map<String, Object>> bulkParams= new List<Map<String, Object>>;
for(/*some iteration*/){
Map<String, Object> flowVariables = new Map<String, Object>{
'body' => htmlBody,
'toAddresses' => toAddresses,
\*some more keys as required by sendEmail action*\
}
bulkParams.add(flowVariables );
};
The approach I was using was to directly invoke the flow inside loop which I am very doubtful if its a good practice as shown
for(/*some iteration*/){
Map<String, Object> flowVariables = new Map<String, Object>{
'body' => htmlBody,
'toAddresses' => toAddresses,
\*some more keys as required by sendEmail action*\
}
Flow.Interview.SendEmail sendEmail = new Flow.Interview.SendEmail(bulkParams);
sendEmail.start();
};
Also adding to that I had few more doubts, the document mentions followinf for email recipients
For the email to send successfully, enter a value for Email Addresses (comma-separated) or Email Addresses (collection). You can use both parameters as long as the combined number of email addresses is five or fewer. This parameter accepts single-value resources of any type. That value is treated as text.
So if we provide email addresses of internal users, it would count in SingleEmail against the limit?