Sample Trigger:
- trigger EmployeeTrigger on Employee__c ( after insert, after update ) {
- List < Messaging.SingleEmailMessage > listMsgs = new List < Messaging.SingleEmailMessage > ();
- for ( Employee__c e : trigger.new ) {
- Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
- msg.setWhatId( e.Id );
- msg.setTemplateId( ’00XU00000011sTd’ );//Id of the Email template
- msg.setToAddresses( new List < String > { ‘[email protected]’ } );
- msg.setTreatTargetObjectAsRecipient( false );
- /*The ID of the contact, lead, or user to which the email will be sent*/
- msg.setTargetObjectId( UserInfo.getUserId() );
- listMsgs.add( msg );
- }
- Messaging.sendEmail( listMsgs );
- }