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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With