5
votes

I'm using the Salesforce REST API to create a Case. I assign the SuppliedEmail field to the email of the user who's creating the case, as well as all other necessary fields. The case is correctly created in salesforce but the auto-response rule set up for it is not triggered. I have verified the rule is working and active, all conditions for the rule are met, so it's not a question of the rule not matching.

The problem is that salesforce is not evaluating/triggering auto-response rules after a Case is created through the API. Through the SOAP API you can set this using the EmailHeader but I can't find a way to set this through the REST API.

To be clear I'm making a POST request to the URI /sobjects/Case with the JSON value of the case itself as the request body.

Is there a way to set the EmailHeader.triggerAutoResponseEmail field to true using the REST API, perhaps through some additional field in the request body?

4

4 Answers

2
votes

Well, less complexity almost always comes at the cost of less features. Loss of API headers are one of them. At least in Java you can consume WSDL properly using many avaiable toolkits, in .NET the WCF is almost borderline useless because MS thinks SOAP headers are not cool (standards be damned).

So, either use WSDL/SOAP or create a workflow rule that will fire on Case creation and send an email to desired address.

2
votes

It is possible.

You need to combine REST API with the APEX code and here's how it's gonna work. Suppose we have a case creation function over REST API working as expected. All you need to do in APEX is add a trigger to handle the following functionality:

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); 
        }   

    }
}

There is a DMLOptions EmailHeader option that has to be modified. If you use the WSDL/SOAP, you can set it before you actually submit the case. Over here the only way to inject it to the Case-creation process is to update just-created case with the new options. But obviously it will take twice more transactions to perform the case insertion.

0
votes

not able to comment (yet) but i wasnt able to get the dml options to trigger the auto-response rules. i ended up just creating the email in apex, which may hit the email limit in an extreme case. the one difference was that i wasnt using the dml through a trigger on the case, i was using it in the rest class that was creating the case, setting case options and inserting using dml.insert(case, options). case was being created, auto response rules not firing

0
votes

option of setting dml options in after create trigger does not work