Question
How can I dynamically add a CC recipient address list in Salesforce Flow?
Answer
To dynamically add CC recipients in Salesforce Flow while sending emails, you can use a combination of Email Alerts and Flows. Here’s a structured explanation of the process and its variations.
Option 1: Using Email Alert with Flow
To achieve this, first, create an Email Alert. Set the object and recipients and add the desired CC recipients in the “Additional Emails” area. Then, in Salesforce Flow, you can invoke the Email Alert and pass the necessary record ID.
- Create an Email Alert for the object you want (e.g., Account). Configure the alert to send to the intended primary recipient, such as the Account Owner. Add the additional email addresses for CC in the “Additional Emails” section. Ensure you choose the correct “From Email Address” in the alert settings.
- Create a Flow that triggers when the criteria are met (e.g., record creation or update). In the Flow, use the “Send Email Alert” action and pass the record ID of the object to ensure the Email Alert is triggered for the correct record.
This approach allows for a straightforward configuration without requiring Apex, making it suitable for most standard use cases.
Option 2: Using Apex-Triggered Emails for Dynamic CC Addresses
If your use case requires dynamically calculating the CC addresses based on specific logic, you can use Apex to send emails programmatically. Here’s an example of how this can be achieved:
public class EmailHelper {
public static void sendEmailWithCC(Id recordId) {
// Create an email
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
// Set the recipient
email.setTargetObjectId(recordId);
// Add CC recipients dynamically
List<String> ccAddresses = new List<String>{ 'cc1@example.com', 'cc2@example.com' };
email.setCcAddresses(ccAddresses);
// Set email template (optional)
email.setTemplateId([SELECT Id FROM EmailTemplate WHERE DeveloperName = 'Your_Template_Name' LIMIT 1].Id);
// Send the email
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
}
}
This code defines a method to send an email with CC addresses dynamically. It creates a Messaging.SingleEmailMessage
object, sets the recipient using setTargetObjectId()
, and adds CC recipients with setCcAddresses()
. The method retrieves a predefined email template using SOQL and assigns it to the message. Finally, it sends the email using Messaging.sendEmail()
.
Option 3: Combining Flow and Dynamic Email Template Updates
For scenarios requiring conditional email content or varying CC addresses, you can update an Email Template dynamically using a Flow and custom fields. Here’s how:
- Configure your Email Alert or Apex code to read these fields and add the email addresses to the CC list before sending.
2. Create custom fields on the object (e.g., Dynamic_CC__c
) to store email addresses.
3. Use a Flow to populate these fields dynamically based on your logic.
These approaches provide flexibility for different scenarios, from simple configurations using Email Alerts to advanced customizations with Apex. Choose the method that best fits your requirements.
Summing Up
To add CC recipients dynamically in Salesforce Flow, you can choose from the following approaches:
- Email Alert with Flow: Create an Email Alert for the desired object, set primary and CC recipients, and invoke it via Flow by passing the record ID. This is a declarative, code-free solution ideal for standard use cases.
- Apex-Triggered Emails: Use Apex for scenarios requiring dynamic CC logic. The provided code example demonstrates creating a
Messaging.SingleEmailMessage
object, setting recipients, adding dynamic CC addresses, and optionally assigning an email template before sending the email programmatically. - Flow with Dynamic Template Updates: Combine Flows with custom fields (e.g.,
Dynamic_CC__c
) to store and update CC addresses dynamically. Email Alerts or Apex can then use these fields to add CC recipients, providing a balance of automation and customization.
Choose the method based on your specific requirements for complexity and control.
Our Salesforce training in Hyderabad is designed to provide you with a comprehensive understanding of the Salesforce platform, enabling you to build a rewarding career in one of the world’s most popular CRM solutions. We cover key areas such as Salesforce Admin, Developer, and AI modules, with a strong focus on hands-on learning through real-time projects. This practical approach ensures that you not only grasp theoretical concepts but also gain the skills needed to solve real-world business challenges. Led by experienced trainers, our course ensures you’re fully prepared for the dynamic demands of the Salesforce ecosystem.
In addition to technical training, our Salesforce training in Hyderabad offers personalized mentorship, expert certification guidance, and interview preparation to help you stand out in the competitive job market. You’ll receive detailed study materials, engage in live project work, and get one-on-one support to fine-tune your skills. Our goal is to ensure you’re not just ready for a certification exam, but are equipped with the practical, job-ready skills that employers value. Join us and take the first step towards mastering Salesforce and advancing your career.