Enhancing Lead Engagement with Automated Welcome Emails in Salesforce


Building strong relationships with leads is crucial for business growth, and Salesforce provides powerful tools to streamline lead management. One key aspect is engaging leads through timely and personalized welcome emails. In this blog post, we will explore a solution that automatically sends a welcome email to a lead one day after they are added as a campaign member to a specific campaign. We will walk you through the implementation steps using Salesforce Scheduled Flow and Apex batch processing, along with a sample scheduled flow, Apex batch code, and email template.

Flow for implementing Lead Campaign Email

Figure 1: Flow for implementing Lead Campaign Email

Setting Entry Conditions

Figure 2: Setting Entry Conditions - CampaignId IsNull False, LeadId isNull False, Status Equals Sent

Setting Field Details

Figure 3: Setting Field Details To Send Email In The Flow

Adding Lead to Campaign Member

Figure 4: Adding Lead to Campaign Member


Figure 5: Welcome Email is Getting Generated Through Flow

Step 2: Creating the Apex Batch Class

Apex Batch Code

    global class LeadcampaignEmail implements Database.Batchable {
    global Database.QueryLocator start(Database.BatchableContext BC) {
        String query = 'SELECT Id, LeadId, Lead.Email, Status, CampaignId FROM CampaignMember';
        return Database.getQueryLocator(query);   
    global void execute(Database.BatchableContext BC, List cmList) {
         List emailsToSend = new List();
        List Mails = new List();
        for (CampaignMember cm : cmList) {
            if((cm.LeadId != Null)&&(cm.Status == 'Sent')){
            Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
                email.setSubject('Lead Test Mail');
                email.setPlainTextBody('Olaa! You have been added to Campaign Member.');  
            Messaging.SendEmailResult[] emailResults = Messaging.sendEmail(emailsToSend);
            System.debug('Email Sent Successfully');
        global void finish(Database.BatchableContext BC) {


Adding Lead to Campaign

Figure 1: Adding Lead to Campaign Member

Welcome Email

Figure 2: Welcome Email is Getting Generated Through Batch Apex Class


Automating the process of sending welcome emails to leads one day after they are added as campaign members in Salesforce can significantly enhance lead engagement and streamline lead management processes. By following the steps outlined in this blog post, you can implement this solution using Salesforce Scheduled Flow and Apex batch processing. Additionally, we have discussed the importance of creating a well-designed email template to make a positive first impression on your leads.

Remember to adapt the scheduled flow, Apex batch class, and email template according to your specific campaign and lead criteria, branding guidelines, and preferences. Salesforce's flexibility allows for customization and tailoring to meet your organization's unique needs. Embrace the power of automation and leverage Salesforce's capabilities to enhance your lead engagement strategies and drive business growth.

For any queries please reach out tosupport@astreait.com.