How do I set DML Options when using the REST API?

My question is nearly identical to an existing question. To summarize the problem, my case owners aren’t receiving an e-mail notification when a new comment is added to their cases. Please view the linked question for the pretty pictures which further describe the issue.

However, the difference between our questions is that I’m creating a case via the REST API (not SOAP). How do I set these magical DML Options? Is it even possible, or are users stuck with one of three workarounds (that I can think of):

  1. Create a workflow e-mail alert (I would vote for this option)
  2. Write an Apex Trigger that hooks into the insert
  3. Use the SOAP API and set the option (not practical if already using the REST API)

Answer

Have you tried using the SForce-Auto-Assign Assignment Rule Header?

The Assignment Rule header is a request header applied when creating or updating Cases or Leads. If enabled, the active assignment rules are used. If disabled, the active assignment rules are not applied. If a valid AssignmentRule ID is provided, the AssignmentRule is applied. If the header is not provided with a request, REST API defaults to using the active assignment rules.

There doesn’t appear to be an equavalent emailHeader. So this probably won’t be sufficient.


Another possible work around – You could use Apex to implement your own REST API that already includes the required DMLOptions.

E.g.

@RestResource(urlMapping='/Case/*')
global with sharing class CaseRestResource {


  @HttpPost
    global static String doPost(String subject) {
        Case newCase = new Case();

        newCase.Subject = subject;
        // Set AccountID, etc...

        Database.DMLOptions dmo = new Database.DMLOptions();
        dmo.emailHeader.triggerUserEmail = true;
        dmo.assignmentRuleHeader.useDefaultRule = true;
        newCase.setOptions(dmo);

        insert newCase;
        return newCase.Id;
    }
}

Attribution
Source : Link , Question Author : Justin Helgerson , Answer Author : Alphaaa

Leave a Comment