I'm trying to run a batch that makes user Inactive if logged in past 2 hours. It runs in to error ": line 1:74 no viable alternative at character" when i try to run this batch. I doubt if the SOQL query condition for Lastlogindate time is correct. Can someone please point to me in right direction?
global class ScheduleInactiveUser Implements Schedulable, Database.Batchable<sObject> {
global void execute(SchedulableContext sc) {
Database.executeBatch(this, 2000);
}
global Database.QueryLocator start(Database.BatchableContext BC) {
string query = 'Select Id, LastLoginDate, IsActive, Name From User Where Profile_Name__c ="Portal JIT User" AND LastLoginDate >= :System.Now().addHours(-2)';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<sObject> scope) {
List<User> UserList = (List<User>) scope;
for(User c : UserList){
c.IsActive = False;
}
update UserList;
}
global void finish(Database.BatchableContext BC) {
}
}
Thank you