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
deepak1.3956330618074822E12deepak1.3956330618074822E12 

Invalid Email address error when trying to put a comment through trigger

The piece of code goes as below. When a case is updated, i am getting the following error. 

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger CommentUpdate caused an unexpected exception, contact your administrator: CommentUpdate: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, E2CP.SetMostRecentPublicComment: execution of AfterInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Invalid to address : null: [] (E2CP): []: Trigger.CommentUpdate: line 12, column 1".

Seems its related to Email to Case premium but not able to figure out how to fix this. 

I am trying to put a comment through this trigger. When the field Case Summary Changed equals Yes, then the case summary in the field Case_Status_Updates__c should be updated as case comments. The code is failing when i am trying to Insert the new comment (last line).

trigger CommentUpdate on Case (before update) {
List<CaseComment> NewComment = new List<CaseComment>();
for(case c:trigger.new){
if(c.Case_Summary_Changed__c == 'Yes'){
CaseComment com = new CaseComment();
com.ParentId = c.id;
com.IsPublished=FALSE;
com.CommentBody= c.Case_Status_Updates__c;
NewComment.add(com) ;
}
}
Insert NewComment;
}

Regards
Deepak
Hargobind_SinghHargobind_Singh
Seems like E2CP package has a trigger that is sending email when comment is being inserted. And, its not finding a valid email address in the field it is looking in. 

You can try to make sure email address exists before adding your comment through trigger, or contact E2CP to help resolve this issue. 


deepak1.3956330618074822E12deepak1.3956330618074822E12
Thank you Hargobind for looking into this issue. Yes. Probably i need to get in touch with E2CP. I dont see any other way in E2CP to resolve this.

Regards
Deepak