You need to sign in to do that
Don't have an account?
Phuc Nguyen 18
Database.BatchableContext no coverage
Hello All,
Trying to figure out why I have no coverage for BatchableContext.
Here is the Class
Here is the Test Class
But no coverage for "global void execute(Database.BatchableContext BC"
ANy suggestions would be apreciated.
Thank you
P
Trying to figure out why I have no coverage for BatchableContext.
Here is the Class
global void execute(Database.BatchableContext BC, List<GridView__c> scope) { system.debug('scope ' + scope); for (GridView__c grid : scope) { grid.Public__c = false; } update scope; }
Here is the Test Class
private class MakePrivateTest { @istest private static void MakePrivateTestTrackers() { list<GridView__c> tList = new List<GridView__c>{ new GridView__c( Name = 'test1', Public__c = false, LastViewedDate__c = null ), new GridView__c( Name = 'test2', Public__c = true, LastViewedDate__c = System.now().addHours(56 * -1) ), new GridView__c( Name = 'test4', Public__c = true, LastViewedDate__c = System.now().addHours(95 * -1) ) }; insert tList; test.startTest(); SchedulableContext sc = null; tmp.execute(sc); MakePrivate tmp = new MakePrivate(); ID batchprocessid = Database.executeBatch(tmp); test.stopTest(); tList = [SELECT Id, Name, Public__c, LastViewedDate__c FROM GridView__c]; system.assertEquals(3, tList.size()); } }
But no coverage for "global void execute(Database.BatchableContext BC"
ANy suggestions would be apreciated.
Thank you
P
In your test class you are using the method addHours but in your private method you are using method addDays. Because your query is looking for values less than (before) 91 days in the past when you are using the addHours it won't match the criteria and have no records to pass as the scope to the execute.
I would change as such:
Please let me know if this helps and if this solves your issue mark it as best answer!
Regards,
Tyler
All Answers
You can check this for reference: https://trailhead.salesforce.com/en/content/learn/modules/asynchronous_apex/async_apex_batch
Also, why dont you put GridView__c instead of the strk__StGridView__c in the execute parameter. Is it another object or the prefix?
That was a typo. And do you want me to run this query?
In your test class you are using the method addHours but in your private method you are using method addDays. Because your query is looking for values less than (before) 91 days in the past when you are using the addHours it won't match the criteria and have no records to pass as the scope to the execute.
I would change as such:
Please let me know if this helps and if this solves your issue mark it as best answer!
Regards,
Tyler
Thank you.
P