You need to sign in to do that
Don't have an account?
Hello Folks
I need help in writing a batch apex class. I have two custom objects Agg_Datas_c and Agg_Datas_Final_c
In the two objects we have same fields they are called 18 GWP,19 GWP, 18 commission, 19 commission also a picklist field.
I have a write a batch apex class in such a way that I should fetch the aggregate data from database in start method.
In execute method I have to calculate variance and variancepercent
In finish method I have to put the data in other object. I am stuck in middle please help me.
global class Batch_AggregateDataTransfer implements Database.Batchable<sObject> {
//start method to fetch the aggregate data from Database.
global Database.QueryLocator start(Database.BatchableContext BC){
string query ='SELECT SUM(X2018_GWP__c),SUM(X2019_GWP__c) FROM Agg_Data_c__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Agg_Data_c__c> Batch){
for(Agg_Data_c__c obj_Agg: Batch){
AggregateResult ar = (AggregateResult)obj_Agg;
Double counter1 = Double.valueOf(ar.get('X2018_GWP__c'));
Double counter2 = Double.valueOf(ar.get('X2019_GWP__c'));
Double variance=counter1-counter2;
Double variancePercent= (counter1-counter2)*0.01;
}
}
global void finish(Database.BatchableContext BC){
{
}
}
}
In the two objects we have same fields they are called 18 GWP,19 GWP, 18 commission, 19 commission also a picklist field.
I have a write a batch apex class in such a way that I should fetch the aggregate data from database in start method.
In execute method I have to calculate variance and variancepercent
In finish method I have to put the data in other object. I am stuck in middle please help me.
global class Batch_AggregateDataTransfer implements Database.Batchable<sObject> {
//start method to fetch the aggregate data from Database.
global Database.QueryLocator start(Database.BatchableContext BC){
string query ='SELECT SUM(X2018_GWP__c),SUM(X2019_GWP__c) FROM Agg_Data_c__c';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext BC, List<Agg_Data_c__c> Batch){
for(Agg_Data_c__c obj_Agg: Batch){
AggregateResult ar = (AggregateResult)obj_Agg;
Double counter1 = Double.valueOf(ar.get('X2018_GWP__c'));
Double counter2 = Double.valueOf(ar.get('X2019_GWP__c'));
Double variance=counter1-counter2;
Double variancePercent= (counter1-counter2)*0.01;
}
}
global void finish(Database.BatchableContext BC){
{
}
}
}
Any update??