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
chiranthchiranth 

Email Notification from apex

Hi 

 

I have written the below trigger on case, If i edit or create a new with a given condition im getting a two mail alert. Please help me on this.

 

trigger EmailNotificationForQuote on Case (after insert, after update, before insert,before update) {
for(Case newCase: Trigger.new){
System.debug(Trigger.new.size()+'------test--');
System.debug(newCase+'------testing--');
if(newCase.Status=='Open'){
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'test@gmail.com'};
mail.setToAddresses(toAddresses);
string subject='Hi';
string body='Hw ttttttttttttttttttttttttttttt u';
mail.setSubject(subject);
mail.setPlainTextBody('Hhhhhhhhhhhhhhhhh');
mail.setHtmlBody(body);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

}
}
}

 

 

Thanks 

Hengky IlawanHengky Ilawan

Hi,

 

Your trigger fire conditions are "after insert, after update, before insert,before update".

So the trigger is actually fired twice (before and after) :)

 

Regards,

Hengky

Ulas KutukUlas Kutuk

One notification from Before Insert the other one comes from After Insert...Just use the right case...