You need to sign in to do that
Don't have an account?
Sudha#a
Any one help on below code write test class
global class Batch_SubscriptionCMRRRollup implements Database.Batchable<SObject>{
global Database.QueryLocator start(Database.BatchableContext context) {
//get all the billing accounts and the related subscriptions
return Database.getQueryLocator([Select Id,Today_s_MRR__c,(Select Id,Zuora__MRR__c,Zuora__Status__c,Zuora__ServiceActivationDate__c from Zuora__Subscriptions__r) from Zuora__CustomerAccount__c]);
}
global void execute(Database.BatchableContext context, List<Zuora__CustomerAccount__c> listOfBillingAccounts) {
//Iterate through all the billing accounts
for(Zuora__CustomerAccount__c iteratingAccount: listOfBillingAccounts){
//Iterate through all the subscriptions
for(Zuora__Subscription__c iteratingSubscription : iteratingAccount.Zuora__Subscriptions__r){
//add only those active subscriptions
if((iteratingSubscription.Zuora__Status__c == 'Active' ||
iteratingSubscription.Zuora__Status__c=='active') &&
iteratingSubscription.Zuora__ServiceActivationDate__c <= Date.Today() &&
iteratingSubscription.Zuora__MRR__c != NULL){
iteratingAccount.Today_s_MRR__c += iteratingSubscription.Zuora__MRR__c;
}
}
}
update listOfBillingAccounts;
}
global void finish(Database.BatchableContext context) {}}
global Database.QueryLocator start(Database.BatchableContext context) {
//get all the billing accounts and the related subscriptions
return Database.getQueryLocator([Select Id,Today_s_MRR__c,(Select Id,Zuora__MRR__c,Zuora__Status__c,Zuora__ServiceActivationDate__c from Zuora__Subscriptions__r) from Zuora__CustomerAccount__c]);
}
global void execute(Database.BatchableContext context, List<Zuora__CustomerAccount__c> listOfBillingAccounts) {
//Iterate through all the billing accounts
for(Zuora__CustomerAccount__c iteratingAccount: listOfBillingAccounts){
//Iterate through all the subscriptions
for(Zuora__Subscription__c iteratingSubscription : iteratingAccount.Zuora__Subscriptions__r){
//add only those active subscriptions
if((iteratingSubscription.Zuora__Status__c == 'Active' ||
iteratingSubscription.Zuora__Status__c=='active') &&
iteratingSubscription.Zuora__ServiceActivationDate__c <= Date.Today() &&
iteratingSubscription.Zuora__MRR__c != NULL){
iteratingAccount.Today_s_MRR__c += iteratingSubscription.Zuora__MRR__c;
}
}
}
update listOfBillingAccounts;
}
global void finish(Database.BatchableContext context) {}}
- First create the test records for Zuora__Subscriptions__r object, as per the conditions in your test class.
- Execute the database method in your test class
- Batch_SubscriptionCMRRRollup object = new Batch_SubscriptionCMRRRollup();
- Database.executeBatch(object);
If my suggestion(s) worked, do let me know by marking the answer as "Best Answer" right under the comment.This will help the rest of the community should they have a similar issue in the future.
Thank you..
Hi Sekar,
Below is the test class logic that you can make use of
@isTest
private class HelloWorldTestClass
{
static testMethod void validateHelloWorld() {
Zuora__CustomerAccount__c ZuoraRec = new Zuora__CustomerAccount__c();
ZuoraRec.Today_s_MRR__c = 'test';
insert ZuoraRec;
Zuora__Subscriptions__c Sub = new Zuora__Subscriptions__c();
sub.Zuora__Status__c = 'Active'
sub.Zuora__CustomerAccount__c = ZuoraRec.id;
insert sub;
Test.starttest();
Batch_SubscriptionCMRRRollup ClassInstance = new Batch_SubscriptionCMRRRollup ();
database.executeBatch(ClassInstance,10);
Test.StopTest();
}
}
I have inserted two records with that ever values that i see in your code. But there may be some other mandatory fields that you may be having it in those object. So please add those fields when inserting the record.
If this helps mark is as answer.
Thanks
Manoj S
Invalid field ServiceActivationDate__c for SObject Zuora__Subscription__c at line 26 column 9
@isTest(SeeallData=true)
private class Batch_SubscriptionCMRRRollup_Test{
static Testmethod void Batch_SubscriptionCMRRRollup_Testmethod(){
Zuora__CustomerAccount__c customer = new Zuora__CustomerAccount__c();
fill some mandatory fields
Insert customer;
Zuora__Subscriptions__c subscription = new Zuora__Subscriptions__c();
subscription.Zuora__CustomerAccountId = customer.Id;
fill some fields here
insert subscription;
Zuora__CustomerAccount__c customertest =[Select id,name,Today_s_MRR__c where id =:customer.id];
system.asertEquals(5555.40,customertest.Today_s_MRR__c);
Test.startTest()
Batch_SubscriptionCMRRRollup objbatch = new Batch_SubscriptionCMRRRollup();
ID batchprocessid = Database.excuteBatch(objbatch);
Test.stopTest();
}
}
https://developer.salesforce.com/page/Getting_Started_with_the_Force.com_Streaming_API