Skip to main content
2 of 3
added 294 characters in body
Chris Duncombe
  • 24.3k
  • 13
  • 77
  • 116

Test class for batch apex

could anyone help in writing a test class for the following code

    global class CaptureLastLoginDate implements Database.Batchable<sObject>{
        
        //This is the query that is passed to the execute method. .
        
        String ids = UserInfo.getUserId();
        String query = 'SELECT id, LastLoginDate,LastLoginDate__c FROM User ';
        
        global database.queryLocator start(Database.BatchableContext BC) {
             System.debug(query);
             return database.getQueryLocator(query);
        }
        //close start method
        global void execute(Database.BatchableContext BC, List<sObject> scope){
            List<Schema.User> u = new List<Schema.User> ();
            for(sObject s: Scope){
                Schema.User inv = (Schema.User)s;
                inv.LastLoginDate__c= inv.LastLoginDate;
                u.add(inv);
                System.debug(u);
            }
            update u;
        }
        
        global void finish(Database.BatchableContext sc){

        }       
   }
Sindoora
  • 735
  • 1
  • 11
  • 24