Activity Forums Salesforce® Discussions Deactivate Users using Workflow

  • Deactivate Users using Workflow

    Posted by David on September 17, 2019 at 6:31 pm

    How can we deactivate users that have not logged in after 10 days using a workflow.

    Laveena replied 3 years ago 2 Members · 1 Reply
  • 1 Reply
  • Laveena

    Member
    September 18, 2019 at 8:29 am

    Hi David,

    List<User> usersToUpdate = new List<User>();
    for(User u : [Select id, IsActive from User where isActive=true and lastLoginDate <= :DATE.TODAY()-10]){
    u.IsActive = false;
    usersToUpdate.add(u);
    }

    if (usersToUpdate.size()>0){
    update usersToUpdate;
    }

    There are some considerations to do this:

    -- one cannot deactivate self user record

    -- Cannot deactivate a user record which is referenced in another user record in a hierarchy custom field

    -- Make a Schedule Class apex and invoke via schedule UI in Salesforce.

    Thanks

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos