Print this page

How to trigger Auto-response rules using REST API?

Knowledge Article Number 000212166
Description Web to lead and web to case auto response rules aren't being triggered when we create records using the REST API. You configure the SOAP API to allow for this using EmailHeader, but not if you use the REST API exclusively. How can you get the auto-response rules enabled using REST. 
Resolution There are two workarounds, one is to create a workflow rule the other is to create an Apex trigger.

1)One option is to create a workflow rule that would fire on Lead/Case creation that would send an email to the correct address. 

2)Or you could also create a trigger on Case/Lead insert where you'd manually set the autoResponse option on the object themselves. Here is a sample that is taken from a stackoverflow forum: 

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

promote demote