Ask Search:
Lindy RoquemoreLindy Roquemore 

How do I trigger an Auto-Resonse Rule when adding a case with the API?

I am adding a Case to SF using the API and it is not triggering the Auto-Responder Rule. It is being entered correctly and I set a simple rule where Case Orign equals Web. I triggers it using Web-To-Case but not when added with the API. Is there something extra needed to make that work?
Best Answer chosen by Moderator (salesforce.com) 
Phillip BlackPhillip Black
You can actually trigger auto-response rules from the API using the Database.DMLOptions class, specifically the emailHeader property. You can read more about it here:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database_dmloptions.htm

I was struggling with the same problem until I discovered that little gem. Hope it helps.

All Answers

Matthew LambMatthew Lamb
Potentially obvious question, but when you are creating them via the API, are you setting the value of the Case Origin field to "Web"?
Lindy RoquemoreLindy Roquemore
Thanks for the quick response. I am setting it to Web. I see it inserted under Cases with all the fields populated to what I set them to, just no email is being sent.
Matthew LambMatthew Lamb
Ah, further investigation from the Help files, appears that cases inserted through the API can't trigger auto-response rules. Where are these coming from? Can you leverage one of the features below instead?

Setting Up Auto-Response Rules

Available in: ProfessionalEnterpriseUnlimited, and Developer Editions

User Permissions Needed
To create auto-response rules:“Customize Application”
An auto-response rule is a set of conditions for sending automatic email responses to lead or case submissions based on the attributes of the submitted record. Applicable leads include those captured through a Web-to-Lead form. Applicable cases include those submitted through a:
  • Self-Service portal
  • Customer Portal
  • Web-to-Case form
  • Email-to-Case message
  • On-Demand Email-to-Case message

You can create as many response rules as you like based on any attribute of the incoming lead or case, but only one rule for leads and one for cases can be active at a time. The email responses are listed in the Activity History related list of the lead or contact and the Email related list on cases.

Lindy RoquemoreLindy Roquemore
I ended up going back to web-to-case/web-to-lead and passed the forms using cURL with PHP. The reason I was using the API was to get around the cross domain issue when using AJAX but this worked out just fine. Thanks.
Phillip BlackPhillip Black
You can actually trigger auto-response rules from the API using the Database.DMLOptions class, specifically the emailHeader property. You can read more about it here:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database_dmloptions.htm

I was struggling with the same problem until I discovered that little gem. Hope it helps.
This was selected as the best answer
Matthew LambMatthew Lamb
Nice find Phillip! Thank you for sharing.
Edward CastroEdward Castro
Phillip, I am having some trouble with this little Gem you found (the article).  But since I am not very familiar with this type of function I am still a bit unsure.  We are using a third party form builder which submits the new cases via the API.o i need this Class/trigger to enable the email header to True so the email gets sent to the customer who is submiting the case.

So do i need to create a trigger, a class, or is there already an existing class that I need to modify?
Edward CastroEdward Castro
is the Database.DMLOptions class an existing class that just needs to be modified?