You need to sign in to do that
Don't have an account?
shravani mil
How to cover Batch class in test class
Below method is not covering in batch class
global void execute(Database.BatchableContext BC, List<SObject> objs) {
system.debug('What is the 1');
List<PriceBookEntry> PbeList=new List<PriceBookEntry >();
Set<String> prods=new Set<String>();
Set<String> pbeids=new Set<String>();
Map<id,SBQQ__ProductOption__c> prodOptions=new Map<id,SBQQ__ProductOption__c>();
for(PriceBookEntry pbe:(List<PriceBookEntry>)objs){
prods.add(pbe.Product2Id);
}
system.debug('prods--'+prods);
for(SBQQ__ProductOption__c opt:[select id,SBQQ__ConfiguredSKU__c,OptionalSKU_Product_Codes__c,SBQQ__OptionalSKU__r.ProductCode,PKorCK_Flag__c,
SBQQ__ProductCode__c,SBQQ__ConfiguredSKU__r.ProductCode,SBQQ__OptionalSKU__c,SBQQ__OptionalSKU__r.name from SBQQ__ProductOption__c where SBQQ__OptionalSKU__c IN :prods]){
if(opt.PKorCK_Flag__c)
prodOptions.put(opt.SBQQ__ConfiguredSKU__c,opt);
}
system.debug('prodOptions--'+prodOptions);
system.debug('prodOptions-size-'+prodOptions.keyset().size());
PackPricingOptionsTriggerHandler handler=new PackPricingOptionsTriggerHandler();
Map<String,Set<string>> Optionskus=handler.getChildProducts(prodOptions,'Batch_PBE Update');
system.debug('optionskusize---'+Optionskus.size()+'optionskue--'+Optionskus.Keyset());
handler.UpdateConfigureSKUPriceValues(Optionskus);
}
global void execute(Database.BatchableContext BC, List<SObject> objs) {
system.debug('What is the 1');
List<PriceBookEntry> PbeList=new List<PriceBookEntry >();
Set<String> prods=new Set<String>();
Set<String> pbeids=new Set<String>();
Map<id,SBQQ__ProductOption__c> prodOptions=new Map<id,SBQQ__ProductOption__c>();
for(PriceBookEntry pbe:(List<PriceBookEntry>)objs){
prods.add(pbe.Product2Id);
}
system.debug('prods--'+prods);
for(SBQQ__ProductOption__c opt:[select id,SBQQ__ConfiguredSKU__c,OptionalSKU_Product_Codes__c,SBQQ__OptionalSKU__r.ProductCode,PKorCK_Flag__c,
SBQQ__ProductCode__c,SBQQ__ConfiguredSKU__r.ProductCode,SBQQ__OptionalSKU__c,SBQQ__OptionalSKU__r.name from SBQQ__ProductOption__c where SBQQ__OptionalSKU__c IN :prods]){
if(opt.PKorCK_Flag__c)
prodOptions.put(opt.SBQQ__ConfiguredSKU__c,opt);
}
system.debug('prodOptions--'+prodOptions);
system.debug('prodOptions-size-'+prodOptions.keyset().size());
PackPricingOptionsTriggerHandler handler=new PackPricingOptionsTriggerHandler();
Map<String,Set<string>> Optionskus=handler.getChildProducts(prodOptions,'Batch_PBE Update');
system.debug('optionskusize---'+Optionskus.size()+'optionskue--'+Optionskus.Keyset());
handler.UpdateConfigureSKUPriceValues(Optionskus);
}
Have you inserted test data into your test class as per your requirement and make sure that your start method is returning at least one record from Database.getQueryLocator query and use below syntax in your test class for covering batch class.
Let me know if this helps :)
Thanks.
Amit Singh
Please check below post for Batch job test class
1) http://amitsalesforce.blogspot.com/2016/02/batch-apex-in-salesforce-test-class-for.html
A sample test class to start