We would like to have an email alert sent to the manager of the departed employee once the user record is deactivated. In that email, we would like to include a link to all that employee's open records and ask the manager to reassign. Can we do this off the User Record?

2 Answers 2


It is not currently possible to create a Workflow to be triggered off the User Record. Its quite a popular idea, so feel free to promote it :) http://success.salesforce.com/ideaview?id=08730000000Br80AAC

You can do this using a trigger on User - the bit to send an email would be easy. Identifying all open records would be slightly more difficult, depending on the Volume. A report seems the most suitable container, depending on the Records which need to be intimated, whether Opportunities, Activities, Cases or others.

I would recommend embedding links to Reports showing Accounts, Opportunities, Cases, Activities, etc owned by the leavers.

The manager can then either use Mass Transfer for the supported Standard Objects, and for other objects, export the Report as CSV, update the owners in the CSV and upload it via Apex DataLoader.

  trigger UserAfter on User (after update) {

    Map<Id, List<User>> mgrToUserMap = new Map<Id, List<User>>{};

    //Collect all the managers who have leavers
    for(User u : trigger.new){
    if (!u.IsActive && u.ManagerId != null){
        List<User> currUsers = mgrToUserMap.get(u.ManagerId);
        if(currUsers == null){
            currUsers = new List<User>{};
            mgrToUserMap.put(u.ManagerId, currUsers);
    }// end for


    for(Id mgrId : mgrToUserMap.keySet()){

    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.saveAsActivity = false;

//only send one email for all leavers per manager
    String emailBody = '';
    for(User usr : mgrToUserMap.get(mgrId))

    emailBody += 'Your subordinate :<b> ' + usr.FirstName + ' ' + usr.LastName + ' </b>has left the organization.<p>' +
         'To view the Accounts owner by this User <a href=' +  System.Url.getSalesforceBaseURL().toExternalForm() + '/'+usr.Id+'>click here.</a> <p>';


    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });



An After update trigger on user Object can be written which sends an email once the user is deactivated to his manager obtained from the manager look up of the user and based on user Id of the user the Ids of the open records (Cases or oppurtunities) can be collected and sent in the body of the email .The Ids are enough to figure the record in salesforce .The managers can be trained appropriately to use Ids to view record and change the owner.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .