function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Barthelemy Laurans 1Barthelemy Laurans 1 

DmlOptions.EmailHeader necessary with lightning/uiRecordApi method ?

Hi,

We created a lightning web component (LWC) which use lightning/uiRecordApi to update a case owner.

Do you know if in such situation, we need to use DmlOptions.EmailHeader like in Apex to trigger notification emails to queue ? If yes, how would we do this ?

Best regards,
Barthélemy
AnudeepAnudeep (Salesforce Developers) 
Hi Barthélemy, 

You can use DmlOptions.EmailHeader because you want trigger email notifications. Creation of a new case is a valid event for 
emailHeader Property in DmlOptions 

To implement this you can build a trigger that fires once your case is created using your wire adapter createRecord(recordInput) under  lightning/uiRecordApi. This is a sample code
trigger WebCaseAssign on Case (after insert) {
    if(trigger.new.size() < 21) {
        for (Case theCase:trigger.new) {
            if(theCase.Origin == 'Web') {
                Database.DMLOptions dmo = new Database.DMLOptions();
                dmo.emailHeader.triggerUserEmail = true;
                dmo.assignmentRuleHeader.useDefaultRule = true;
                theCase.setOptions(dmo);
                Database.update(theCase);    
            }      
        }
    }
}

Here are the list of available properties 

If you find this information helpful, please select this answer as best. It may help others in the future. Thank You!

Anudeep
Barthelemy Laurans 1Barthelemy Laurans 1
Hi,

Thanks for your answer. I think you miss the target here ...

Here is why :
  • I'm not creating a case, I'm updating it
  • Question is not about how to use DmlOptions.EmailHeader but
    • Is it necessary when doing updates with lightning/uiRecordApi ?
    • Do we have a way to give lightning/uiRecordApi updateRecord method options which is equivalent to Apex DmlOptions.EmailHeader ?
  • I certainly don't want to update a record I just created to avoid any misconception leading to recurcive trigger leading to governor limits
Currently I'm updating my record using lightning/uiRecordApi updateRecord method. This doesn't require any Apex. If I can continue to not use any Apex it would be amazing.

Let's say DmlOptions.EmailHeader is required when doing updates with lightning/uiRecordApi and there is no way to give updateRecord method options for that. In such case, I will simply write an Apex method that make the update with correct DmlOptions. I just want to avoid this way around.

Best regards,
Barthélemy