+ Start a Discussion
jai.sjai.s 

How to automatically Deactivate the Licenses, if those are not using from last one month?

Hi,
We have 1000 licenses in my org, in that few are not login regularly, I what to deactivate them automatically those are not using from last one month.

Please any one can suggest me, how can we achieve this?

Regards,
Shaik
Best Answer chosen by jai.s
EnreecoEnreeco
Hi, you can create a Scheculed Apex Job (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm) that executes daily and that executes a simple query:
String query = 'Select Id From User Where LastLoginDate < ' + system.now().addMonths(-1).format('yyyy-MM-dd') + 'T00:00:00.000Z and IsActive=false';
//you can add ProfileId in the query or even UserType, depends on your needs, you can even exclude admin users
List<User> uList = Database.query(query);
for(User uList : usrs) {
    usr.IsActive = false;
}

update uList;

This way every user that do hasn't logged in in the last month will be automatically disabled.

--
May the Force.com be with you!

All Answers

EnreecoEnreeco
Hi, you can create a Scheculed Apex Job (http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_scheduler.htm) that executes daily and that executes a simple query:
String query = 'Select Id From User Where LastLoginDate < ' + system.now().addMonths(-1).format('yyyy-MM-dd') + 'T00:00:00.000Z and IsActive=false';
//you can add ProfileId in the query or even UserType, depends on your needs, you can even exclude admin users
List<User> uList = Database.query(query);
for(User uList : usrs) {
    usr.IsActive = false;
}

update uList;

This way every user that do hasn't logged in in the last month will be automatically disabled.

--
May the Force.com be with you!
This was selected as the best answer
jai.sjai.s
Hi Enreeco,

Thanks for your support.

Regards,
Shaik