+ Start a Discussion
Robert Baker 4Robert Baker 4 

Send customer an email after CaseComment

Hello,

I've been having some issues getting emails to send when inserting a CaseComment. I'm currently using the nForce npm module as my program is written for use with nodejs.

Some sample code 

const casecoment = nforce.createSObject('CaseComment', {
	CommentBody: 'API-based nForce test for a comment',
	ParentId: cParentId,
	IsPublished,
});

org.insert({
	sobject: casecoment,
	oauth,
}, (err, resp) => {
	if (err) {
		console.log("Could post to case comment");
		console.log(JSON.stringify(err));
	}
	else {
		console.log('posting comment worked!');
	}
});

What I'm wondering is what else I may need to do in order to get emails for case updates to the contact sent out. I'm able to get emails as the case owner without any issues. On the CaseComment sObject page, I saw that "IsNotificationSelected" is a column I can read, but isn't something I can create as I just receive an error when adding it to my code above.

Is there a way to programmatically have the notification email sent out like the "Send Customer Notification" in the website interface?

RituSharmaRituSharma
For this you have to use Database.Insert method along with DML options. You may send DML options in string from your lightning component and in APEX you may use Database.DMLOptions.Class to deserialize the string.

So APEX code will be like below:

Database.DMLOptions dmlOptions = (Database.DMLOptions) JSON.deserialize(dmlOptionsStr, Database.DMLOptions.Class);
results = Database.Insert(sObjectList,dmlOptions);

And lightning code will be like below:
var dmlOptions = {
            "optAllOrNone" : true,
            "EmailHeader" : {
                    "triggerOtherEmail": true,
                    "triggerUserEmail": true,
             }
 };
 
Stringify dmlOptions using below line and use it to send to APEX:
JSON.stringify(dmlOptions)