Activity Forums Salesforce® Discussions How to include a unique coupon code to each lead in auto response email

  • How to include a unique coupon code to each lead in auto response email

    Posted by sai on February 16, 2021 at 5:14 am

    Iam newly Joined here, I am not sure whether I can ask this type of questions here. If not please suggest me the best forum to post this question
    I have a requirement to retrieve a coupon code from API and include that in a auto response email to leads after lead is created. My thought is to create a custom object coupon under lead and store the coupon details for each lead after retrieving it from api. Their API is not ready yet I need to test with mock API and give them request and response details to create an API.
    Can I create a flow for the whole process, like after lead insert, apex code to retrieve the coupon code and save it in Leads coupon record and send an auto email to lead with coupon code attached.
    Any Ideas would be greatly appreciated.

    Aditya replied 1 year, 7 months ago 2 Members · 1 Reply
  • 1 Reply
  • Aditya

    Member
    February 19, 2021 at 2:31 pm
    trigger AfterCaseInsert on Case (after insert) { 
        if (trigger.isAfter && trigger.isInsert) { 
            List<Case> newlyInsertedCases = [SELECT Id From Case WHERE Id IN :trigger.new]; 
            Database.DMLOptions autoResponseOptions = new Database.DMLOptions(); 
            autoResponseOptions.EmailHeader.triggerAutoResponseEmail = true; 
            for (Case c : newlyInsertedCases ) { 
                Database.update(c, autoResponseOptions); 
            } 
        } 
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos