0

Here is the scenario that I'm running in to. I need to able to pull users that logged in past 2 hours but not last 30 Minutes. I tried every possible way to filter this in but since we can't Use lastlogin date field in formula, its really difficult to parse this in Apex.

  global Database.QueryLocator start(Database.BatchableContext BC) {  
        DateTime LoggedInPast2Hours = System.now().addMinutes(-120);
        DateTime LoggedInPast30Mins = System.now().addMinutes(-30);
        string query = 'Select Id, LastLoginDate, IsActive, Name From User ' +  
                         ' Where Profile_Name__c = \'Portal JIT User\' AND' + 
                                 ' LastLoginDate >= :LoggedInPast2Hours AND ' + 
                                 ' LastLoginDate <=: LoggedInPast30Mins ';
        return Database.getQueryLocator(query);
         }
4
  • so -- what is not working? also; you can use static SOQL rather than dynamic SOQL
    – cropredy
    Mar 3 at 22:32
  • The batch updates the users to Inactive by pulling the records retrieved in SOQL but SOQL is not pulling correct records.
    – Saaki
    Mar 3 at 22:35
  • it works for me ....you should test using Developer Console Execute Anonymous to verify the users you are expecting have the proper value in Profile_Name__c
    – cropredy
    Mar 3 at 22:43
  • Guess what, I was expecting old records that falls outside 2 hour window to be updated but I was wrong. There is only one record that falls in 2 hour window and outside 30 minutes and its working as expected. Was working the whole time. Thanks anyway!!
    – Saaki
    Mar 3 at 22:55
0

Guess what, I was expecting old records that falls outside 2 hour window to be updated but I was wrong. There is only one record that falls in 2 hour window and outside 30 minutes and its working as expected. Was working the whole time. Thanks anyway!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.