Activity Forums Salesforce® Discussions Deactivate Users using Workflow

  • 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