function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sudha#aSudha#a 

Any one help me trigger test class


trigger SubscriptionCMRRRollup on Zuora__Subscription__c (after insert, after update, after delete)
{
    
    Set<Id> BillingAccId = new Set<Id>();
    List<Zuora__CustomerAccount__c> BillingAccList = new List<Zuora__CustomerAccount__c>();
    
    if(Trigger.isInsert){
        for(Zuora__Subscription__c s: Trigger.new)
            BillingAccId.add(s.Zuora__CustomerAccount__c);
    }
    if(Trigger.isUpdate || Trigger.isDelete){
        for(Zuora__Subscription__c s: Trigger.old)
            BillingAccId.add(s.Zuora__CustomerAccount__c);
    }
    Map<id,Zuora__CustomerAccount__c> BillingAccMap = new Map<id,Zuora__CustomerAccount__c>([select id, Today_s_MRR__c from Zuora__CustomerAccount__c where id IN :BillingAccId]);
    
    for(Zuora__CustomerAccount__c sub:[Select Id,Today_s_MRR__c,( Select Id,Zuora__MRR__c from Zuora__Subscriptions__r) from Zuora__CustomerAccount__c where Id IN :BillingAccId]){
        for(Zuora__Subscription__c z: sub.Zuora__Subscriptions__r){
            BillingAccMap.get(sub.Id).Today_s_MRR__c += z.Zuora__MRR__c;
            BillingAccList.add(BillingAccMap.get(sub.Id));
        }
    }
    update BillingAccList;
}
 
deepak balur 19deepak balur 19
I can give you psuedo code steps and then you can fill in using relevant fields from your env:
public class TestSubscription {

  static testmethod void CrAccount() {
   //write code to create a account

  // get account id
  }

  static testmethod void InsSubscr() {
   //write code to create a Insert Subscription record using a for loop for 100 records

  // Use all the variables that you have defined in your trigger code
  }

  static testmethod void UpdSubscr() {
   //write code to update Subscription record using a for loop for 100 records

  // Use all the variables that you have defined in your trigger code
  }

  static testmethod void DelSubscr() {
   //write code to delete Subscription record using a for loop for 100 records

  // Use all the variables that you have defined in your trigger code
  }

}