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
Che SFDCChe SFDC 

Trigger on Event for Email Alert

Standard Salesforce functionalty doesnt allow us to send Email Alert on Events (Task/Events - Activities). I need a trigger which will notify me or my user(s) when new Event is entered in Salesforce when custom checkbox field "Conference__C" is marked as yes. Can someone please help me with a code?
 
Best Answer chosen by Che SFDC
John PipkinJohn Pipkin
this should work...
 
Trigger notifyonEvent on Event (after insert){

	List<Messaging.SingleEmailMessage> newEmails = new List<Messaging.SingleEmailMessage>();
	for(Event e :Trigger.new){
	
		if(E.Conference__c){
			Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
		        
		    mail.setSubject('Your Subject Here');
		    mail.setToAddresses(new String[] {'email #1', 
		                                        'email # 2 (if you want)'});
		    String emailBody = 'Your email body';
		    mail.setPlainTextBody(emailBody);
		    newEmails.add(mail);
	    }
    }

    messaging.sendEmail(newEmails);
}

 

All Answers

John PipkinJohn Pipkin
this should work...
 
Trigger notifyonEvent on Event (after insert){

	List<Messaging.SingleEmailMessage> newEmails = new List<Messaging.SingleEmailMessage>();
	for(Event e :Trigger.new){
	
		if(E.Conference__c){
			Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
		        
		    mail.setSubject('Your Subject Here');
		    mail.setToAddresses(new String[] {'email #1', 
		                                        'email # 2 (if you want)'});
		    String emailBody = 'Your email body';
		    mail.setPlainTextBody(emailBody);
		    newEmails.add(mail);
	    }
    }

    messaging.sendEmail(newEmails);
}

 
This was selected as the best answer
Che SFDCChe SFDC
Thank you John, this works great!! Many thanks!