You need to sign in to do that
Don't have an account?
vasu sfdc_21
CPQ Trigger test class
Hi All,
Can someone help me with Trigger test class for the below trigger?
Trigger SubscriptionTrigger on SBQQ__Subscription__c (After Insert,After update){
Map<Id,Set<String>> contractIdVsProductGrp = new Map<Id,Set<String>>();
Set<Id> contractIdset = new Set<Id>();
List<Contract> lstUpdateContracts = new List<Contract>();
for(SBQQ__Subscription__c sub:Trigger.New){
ContractIdset.add(sub.SBQQ__Contract__c); //fetcting Contract ids - lookup to SBQQ__Subscription__c object
}
//fetching all subscription records(Product groups names) related to contracts
for(SBQQ__Subscription__c sb : [Select Id,SBQQ__Contract__c,SBQQ__Product__c,SBQQ__Product__r.Product_Group__c from SBQQ__Subscription__c where SBQQ__Contract__c in :contractIdset])
{
if(contractIdVsProductGrp.containsKey(sb.SBQQ__Contract__c)){
contractIdVsProductGrp.get(sb.SBQQ__Contract__c).add(sb.SBQQ__Product__r.Product_Group__C);
}
else{
contractIdVsProductGrp.put(sb.SBQQ__Contract__c, new Set<String>{sb.SBQQ__Product__r.Product_Group__C});
}
}
//Subscriptions parent (contract) needs to update with Product groups name
for(Id contId:contractIdset){
Contract parentContract = new Contract(Id = contId);
String prdGrps = '';
if(!contractIdVsProductGrp.isEmpty() && contractIdVsProductGrp.containsKey(contId)){
for(String prdGrpStr : contractIdVsProductGrp.get(contId)){
if(prdGrps == ''){
prdGrps = prdGrpStr;
}
else{
prdGrps += ','+prdGrpStr;
}
}
parentContract.Product_Group__C = prdGrps;
lstUpdateContracts.add(parentContract);
}//if close
}//for loop close
//update contracts
if(lstUpdateContracts.size() > 0){
update lstUpdateContracts;
}
}
Can someone help me with Trigger test class for the below trigger?
Trigger SubscriptionTrigger on SBQQ__Subscription__c (After Insert,After update){
Map<Id,Set<String>> contractIdVsProductGrp = new Map<Id,Set<String>>();
Set<Id> contractIdset = new Set<Id>();
List<Contract> lstUpdateContracts = new List<Contract>();
for(SBQQ__Subscription__c sub:Trigger.New){
ContractIdset.add(sub.SBQQ__Contract__c); //fetcting Contract ids - lookup to SBQQ__Subscription__c object
}
//fetching all subscription records(Product groups names) related to contracts
for(SBQQ__Subscription__c sb : [Select Id,SBQQ__Contract__c,SBQQ__Product__c,SBQQ__Product__r.Product_Group__c from SBQQ__Subscription__c where SBQQ__Contract__c in :contractIdset])
{
if(contractIdVsProductGrp.containsKey(sb.SBQQ__Contract__c)){
contractIdVsProductGrp.get(sb.SBQQ__Contract__c).add(sb.SBQQ__Product__r.Product_Group__C);
}
else{
contractIdVsProductGrp.put(sb.SBQQ__Contract__c, new Set<String>{sb.SBQQ__Product__r.Product_Group__C});
}
}
//Subscriptions parent (contract) needs to update with Product groups name
for(Id contId:contractIdset){
Contract parentContract = new Contract(Id = contId);
String prdGrps = '';
if(!contractIdVsProductGrp.isEmpty() && contractIdVsProductGrp.containsKey(contId)){
for(String prdGrpStr : contractIdVsProductGrp.get(contId)){
if(prdGrps == ''){
prdGrps = prdGrpStr;
}
else{
prdGrps += ','+prdGrpStr;
}
}
parentContract.Product_Group__C = prdGrps;
lstUpdateContracts.add(parentContract);
}//if close
}//for loop close
//update contracts
if(lstUpdateContracts.size() > 0){
update lstUpdateContracts;
}
}
The code provided in question does not highlight uncovered lines.Also,since the code is huge and requires an understanding of your implementation, it might not be possible to provide exact edit suggestions. However, the below articles give a good insight into how coverage can be improved
https://salesforce.stackexchange.com/questions/244794/how-do-i-increase-my-code-coverage-or-why-cant-i-cover-these-lines
Code Coverage Best Practices
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_code_coverage_best_pract.htm
Checking Code Coverage
https://help.salesforce.com/articleView?id=code_dev_console_tests_coverage.htm&type=5
Deployment related code coverage issues
https://help.salesforce.com/articleView?id=000335222&type=1&mode=1
Examples of CPQ test classes:
https://help.salesforce.com/articleView?id=000317379&language=en_US&mode=1&type=1
https://salesforce.stackexchange.com/questions/301314/test-class-passing-but-not-getting-any-code-coverage
If this information helps, please mark the answer as best. Thank you