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
Hong_YanHong_Yan 

Emails not being sent on new case comment through apex

I've been trying to do this by setting the DML options, but it doesn't seem to be working.

 

Stuck as to what I'm doing wrong.

This is the code I'm using:

 

    public PageReference doSave()
    {
        List<sObject> sList=setCon.getSelected();
        List<CaseComment> ccList=new List<CaseComment>();
        for(sObject s:sList)
        {
            s.Put('Status',CaseStatus);
            s.Put('Reason',CaseReason);
            if(!String.isBlank(Comment))
            {
                ccList.Add(new CaseComment(CommentBody=Comment, ParentId=(Id)s.Get('id'), isPublished=PublicComment));
            }
        }
        if(!ccList.isEmpty())
        {
            Database.DMLOptions dmlOpts = new Database.DMLOptions();
            dmlOpts.EmailHeader.triggerAutoResponseEmail = true;
            dmlOpts.EmailHeader.triggerOtherEmail = true;
            database.insert(ccList,dmlOpts);
        }
        return setCon.save();
    }

Hengky IlawanHengky Ilawan
Hi,

Is that in sandbox?
Have you checked the email deliverability settings?

-Hengky-
AhmadAhmad
Actually, to trigger email to queue email or queue members, one needs to include the following option:
dmlOpts.EmailHeader.triggerUserEmail = true;
See Force.com Apex Code Developer's Guide (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_class_Database_EmailHeader.htm).