Find your content:

Search form

You are here

Can a Workflow Rule be created against a User Record? i.e. send an email alert to their manager once the record is deactivated?

 
Share

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?


Attribution to: Denise

Possible Suggestion/Solution #1

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);
        }
        currUsers.add(u);
    }
    }// end for

    if(!mgrToUserMap.isEmpty()){
    Messaging.reserveSingleEmailCapacity(mgrToUserMap.size());

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

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

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

//SEND LINKS TO REPORTS SHOWING ACCOUNTS, OPPORTUNITIES, CASES, ACTIVITES OWNED BY LEAVER
    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>';

    mail.setHtmlBody(emailBody);

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

    }

    }

Attribution to: techtrekker

Possible Suggestion/Solution #2

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.


Attribution to: Mohith Shrivastava
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/3791

My Block Status

My Block Content