Email alert on creation of User in Salesforce

Sample Trigger for Email alert on creation of User:

trigger welcomeUser on User (after insert)
{   
    for(user u:trigger.new)
    {               
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();       
        String[] toAddresses = new String[] {u.Email};       
        mail.setToAddresses(toAddresses);       
        mail.setSubject('Welcome');      
        mail.setUseSignature(false);       
        mail.setHtmlBody('<html>Hi ' + u.Name + ',<br>Welcome to our organization');       
       Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });           
    }
}

No comments:

Post a Comment