We found an issue when portal users leave comments on our cases. Email notifications to the case owners were not being sent. So I did change the code to use the setoptions method.
The problem is that now, validation messages (validation rules triggered) are not showing on the page. Any idea how to fix this? Thanks in advance.
List<CaseComment> toInsert = new List<CaseComment>();
for (CaseComment newCom : newComments) {
if (newCom.CommentBody! = null) {
newCom.parentId = cId;
newCom.IsPublished = true;
toInsert.add(newCom);
}
}
try {
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail = true;
database.insert(toInsert, dlo);
} catch(DmlException ex) {
ApexPages.addMessages(ex);
}