You need to sign in to do that
Don't have an account?
Linda 98
Lastmodifieddate in test class for batch schedule class
I am changing one particular field by checking lastmodifeddate in my code.All works fine but i am struck with test class.I am chnaging multiple records from multiple objects so my batch class looks like below.
my test class is as below which get 58% of coverage.How can i get lastmodified date and cover rest of code.please help.
global class editrecords implements Database.Batchable<string>, Schedulable{ global boolean bool = false; global Iterable<string> start(Database.BatchableContext ctx) { return new list<String> { 'CO__c', 'CO2__c', 'CO3__c','CO4__c'}; } global void execute(Database.BatchableContext ctx, list<string> listObj) { list<sObject> editrecords = new list<sObject>(); for(string strObjName : listObj) { for(sObject objsObject : database.query('Select Id from ' + strObjName + ' where LastModifiedDate < LAST_N_DAYS:36')) { editrecords.add(objsObject); else { b = true; break; } } } update editrecords; } global void finish(Database.BatchableContext ctx) { } global void execute(SchedulableContext sc){ Database.executebatch(new editrecords ()); } }
my test class is as below which get 58% of coverage.How can i get lastmodified date and cover rest of code.please help.
@isTest Public class testeditrecords{ static testMethod void testMethod1(){ CO__c CO =new CO__c(Name='testdata'); insert CO; CO2__c co2 =new co2__c(Name='testdata'); insert co2; Co3__c co3 =new Co3__c(Name='test2'); insert co3; for(CO__c c:[Select ID from CO__c where createddate=TODAY]){ Test.startTest(); editrecords obj = new editrecords(); Database.executeBatch(obj); Test.stopTest(); } } }
Let us know if this will help you
All Answers
Mark as best answer, If it resloves !! Create date field in test class for these object CO__c and update it.
So you will get created date as last modified date.
Mark as resloved if it helps :) :)
Thanks,
Bhanu Prakash
visit ForceLearn.com (https://www.forcelearn.com/)
Let us know if this will help you