You need to sign in to do that
Don't have an account?
sfdc dev 2264
Batch class execute method not calling in test class
Hi,
I have an execute method which isnot covering in my test class , let me know how to cover it
I am having 3 method under execute method which i am calling seperately
MY BATCH CLASS EXECUTE METHOD
// The execute method will call three methods
global void execute(Database.BatchableContext bc, List<Contract__c> scope) {
ContractfieldsupdateonAccount(scope);
contractcommencementdate(scope);
contractexpirydate(scope);
}
MY TEST CLASS :
Test.startTest();
list<Contract__c> Cons = new list<Contract__c>();
Set<id> contractId = new Set<id>();
for(Contract__c c :Cons )
{
contractId.add(c.id);
}
ContractBatchTriggerHandler batchObj = new ContractBatchTriggerHandler(contractId);
List<contract__c> co=[SELECT Status__c, Account__c FROM Contract__c WHERE Status__c = 'Signed by Customer'];
ContractBatchTriggerHandler.contractcommencementdate(co);
ContractBatchTriggerHandler.contractexpirydate(co);
ContractBatchTriggerHandler.ContractfieldsupdateonAccount(co);
Database.executeBatch(batchObj,2);
Test.stopTest();
Kindly help me how to fix this issue
Thanks
I have an execute method which isnot covering in my test class , let me know how to cover it
I am having 3 method under execute method which i am calling seperately
MY BATCH CLASS EXECUTE METHOD
// The execute method will call three methods
global void execute(Database.BatchableContext bc, List<Contract__c> scope) {
ContractfieldsupdateonAccount(scope);
contractcommencementdate(scope);
contractexpirydate(scope);
}
MY TEST CLASS :
Test.startTest();
list<Contract__c> Cons = new list<Contract__c>();
Set<id> contractId = new Set<id>();
for(Contract__c c :Cons )
{
contractId.add(c.id);
}
ContractBatchTriggerHandler batchObj = new ContractBatchTriggerHandler(contractId);
List<contract__c> co=[SELECT Status__c, Account__c FROM Contract__c WHERE Status__c = 'Signed by Customer'];
ContractBatchTriggerHandler.contractcommencementdate(co);
ContractBatchTriggerHandler.contractexpirydate(co);
ContractBatchTriggerHandler.ContractfieldsupdateonAccount(co);
Database.executeBatch(batchObj,2);
Test.stopTest();
Kindly help me how to fix this issue
Thanks
I'd also recommend to separate testing of the 3 static ContractBatchTriggerHandler methods from testing the execute method; to add some asserts ; and to move Test.startTest() down in your code before you actually start testing.
You should have atleast 1 record to process in order to hit the execute method. The above statement will fail as long as you don't have anything in your SOQL. Also, when you are creating the Contract__c records, make sure you have the Status__c = 'Signed by Customer'.