1

I would like to set up a system in which we can automatically de-activate a User account for a terminated employee. As it is now, our HR notifies us of a termination through an email and we inturn manually deactive the Salesforce User ID. Ideally, we would be able to set up a process which would use a spreadsheet list from HR to update the User files.

We could set up the process to automatically run a task using Informatica, but I'm not sure what exactly would need to be updated besides the Active field. Is it necessary to remove their license as well ? If so, how ? Anything else ?

4
  • 1
    You could write an email service and have HR send the email to a specific address in a specific format and have that auto deactivate those Users. That'd be my approach. Nov 16, 2016 at 18:30
  • Also, just set isActive = true, that's it Nov 16, 2016 at 18:31
  • 2
    @caleb.breckon - Shouldn't it be isActive = false
    – Eric
    Nov 16, 2016 at 19:26
  • Do you have Single Sign-On setup in your org?
    – o-lexi
    Nov 16, 2016 at 20:03

1 Answer 1

4

An outline of my comment above

Develop > Email Services

Create a new email address. Either give this email address to HR and have them save it in their Address Book, or set up a friendly named account ([email protected]) on your Server that forwards every email from certain addresses to that Salesforce email.

Tell HR they are to always send in the format

Subject: Termination
Body: employeeid1, employeeid3, employeeid4

Your email class will be something like this

global class InboundEmailHandler implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        if ( email.subject == 'Termination' ) {
            TerminateController.getInstance().terminate(email.plainTextBody);
        }
        return result;
    }
}

And your TerminateController will be something like this

public class TerminateController {
     @TestVisible private static final TerminateController INSTANCE = new TerminateController();
    public static TerminateController getInstance() {
        return INSTANCE;
    }
    public void terminate(String commaSeparatedString) {
        String[] employeeids = commaSeparatedString.split(',');
        List<User> users = [SELECT isActive FROM User WHERE employee_Id__c IN: employeeids and isActive = true];
        for ( User u : users ) {
            u.isActive = false;
        }
        update users;
    }
}

I haven't verified / optimized any of the above, but it should be pretty close.

7
  • I think having a controller is overkill for something so short, and lacks error handling, but it's essentially correct. Nicely done.
    – sfdcfox
    Nov 16, 2016 at 19:11
  • Thank you so much. One question : Is the isActive field really the only thing which needs to be changed ? I thought I needed to remove licenses ? Or can I just leave the licenses in there since the account is deactive ? Will my license count automaticaly update ? Thanks again.
    – Zoom_v
    Nov 16, 2016 at 19:48
  • Agreed, it was meant as a point of reference not a copy paste solution. Nov 16, 2016 at 20:39
  • 1
    You can just leave the license there and your license count will automatically increment by 1 when you deactivate. Nov 16, 2016 at 20:39
  • @caleb.breckon - thanks again. I am trying to use the code you put up here. I know it was only meant as a reference. I keep trying to use it ; I was hoping I'd be able to walk through the errors I knew would come up. Right now I'm just trying to get the controller to controller to save and I keep getting "expecting left curly bracket, found '(' at line 1 column 32 ". That seems weird. I think there is an extra right bracket on your code, so I figured removing the one at the end would solve the problem, but it didn't. Any suggestions ? I'm a newbie in this area. Thanks.
    – Zoom_v
    Nov 16, 2016 at 20:56

You must log in to answer this question.

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