Email alert on creation of User in Salesforce

Email alert on creation of User in Salesforce

Sample Trigger for Email alert on creation of User:

trigger welcomeUser on User ( after insert ) {   


   List < Messaging.SingleEmailMessage > mails = newMessaging.SingleEmailMessage();

    for ( user u:trigger.new ) {               

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();       
        String[] toAddresses = new String[] { u.Email };       
        mail.setToAddresses( toAddresses );       
        mail.setSubject( ‘Welcome’ );         
        mail.setHtmlBody( ‘<html>Hi ‘ + u.Name + ‘,<br/>Welcome to our Organization’ );    
        mails.add( mail );

    }   
    Messaging.sendEmail( mails );        
   
}

Leave a Reply