You need to sign in to do that
Don't have an account?
GYAN ANDRUS
VEry urgent i have a trigger for email notification,i am getting email Comments-Null,If comments are not there i have to get empty,
trigger TaskCompletedTrigger on Task (before update ) { Set ownerIds = new Set(); for(Task tsk: Trigger.New){ if(tsk.Status=='Completed' && Trigger.oldMap.get(tsk.Id).Status != 'Completed'){ ownerIds.add(tsk.CreatedById); } } Map userMap = new Map([select Name, Email from User where Id in :ownerIds]); Map mapCase = new Map([SELECT Id,Email__c,CaseNumber,Case_Request_Type__c,CreatedDate,Status,Description,Type,Subject,Contact.Name,Contact.Email,Contact.MobilePhone FROM Case]); List emailMsglist=new List(); for(Task tsk : Trigger.New) { Case caseObj = mapCase.get( tsk.WhatId ); if(tsk.Status=='Completed' && Trigger.oldMap.get(tsk.Id).Status != 'Completed'){ User theUser = userMap.get(tsk.CreatedById); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); String[] toAddresses = new String[] {theUser.Email}; mail.setToAddresses(toAddresses); mail.setSubject('A task has been updated'); String template = 'Hello {0}, \nYour task has been Completed. Here are the details - \n\n'; template+= 'CASE- {1}\n'; template+= 'Subject - {2}\n'; template+= 'Due Date - {3}\n'; template+= 'Comments - {4}\n'; template+= 'Status - {5}\n'; String duedate = ''; String Commentsdes = ''; if (tsk.ActivityDate==null) duedate = ''; if (tsk.Description==null ) Commentsdes = 'No Comments'; else duedate = tsk.ActivityDate.format(); Commentsdes = tsk.Description; List args = new List(); args.add(theUser.Name); args.add(mapCase.get(tsk.WhatId).CaseNumber); args.add(tsk.Subject); args.add(duedate); args.add(tsk.Description); args.add(tsk.Status); String formattedHtml = String.format(template, args); mail.setPlainTextBody(formattedHtml); emailMsglist.add(mail); } } Messaging.SendEmail(emailMsglist); }
You have to check if description is null or empty at line number 39 and update the value accordingly. Please see below complete code:
Please mark this as best answer if this resolves problem.
Thanks
All Answers
You have to check if description is null or empty at line number 39 and update the value accordingly. Please see below complete code:
Please mark this as best answer if this resolves problem.
Thanks
Thank You so much