+ Start a Discussion
Sudha#aSudha#a 

can u help me amit(i want test class) belo code

public class Batch_SubscriptionCMRRRollup implements Database.Batchable<SObject>{

public Database.QueryLocator start(Database.BatchableContext context) {

    return Database.getQueryLocator([Select Id,Today_s_MRR__c,(Select Id,Zuora__MRR__c from Zuora__Subscriptions__r) from Zuora__CustomerAccount__c]);
}

public void execute(Database.BatchableContext context, List<Zuora__CustomerAccount__c> scope) {

System.debug('@@scope'+scope);
for(Zuora__CustomerAccount__c acc: scope){
    for(Zuora__Subscription__c z: acc.Zuora__Subscriptions__r){
        acc.Today_s_MRR__c += z.Zuora__MRR__c;
    }
}

}

public void finish(Database.BatchableContext context) {}
}
Amit Chaudhary 8Amit Chaudhary 8
Please try below test class. Please create test data according to your org
@isTest 
public class Batch_SubscriptionCMRRRollupTest 
{
    static testMethod void testMethod1() 
    {
        Account acct = new Account(Name = 'First last');
        insert acct;
        
        Zuora__CustomerAccount__c bAcc=new Zuora__CustomerAccount__c();
        bAcc.Name='Test Bill';
        bAcc.Zuora__Account__c=acct.Id; 
       // bAcc.Zuora__BillCycleDay__c = '1st of the month';
       // bAcc.Zuora__BillToAddress1__c = '125 fake street';
       // bAcc.Zuora__BillToAddress2__c = '';
       // bAcc.Zuora__BillToState__c = 'UT';
       // bAcc.Zuora__BillToPostalCode__c = '84058';
       // bAcc.Zuora__BillToCity__c = 'Provo';
       // bAcc.Zuora__BillToCountry__c = 'US';
       // bAcc.Send_to_Collections__c = false;
       // bAcc.Cancel_Billing_Account__c = false;
        Insert bAcc;
        
        Test.startTest();

            Batch_SubscriptionCMRRRollup obj = new Batch_SubscriptionCMRRRollup();
            DataBase.executeBatch(obj); 
            
        Test.stopTest();
    }
}

Let us know if this will help you
 
Sudha#aSudha#a
thaks alot
 
Sudha#aSudha#a
u r my favorate amit