I have a requirement where i need to update amount pipeline field in accounnt object for the newly created account the value need to be come from sum of opportunities associated with that particular account.
following batch class written by me can some one help here
public class AccountNewlyCreated implements Database.Batchable<sobject>
{
public decimal sum;
public database.QueryLocator start(database.batchablecontext bc)
{
string query ='select id,name,(select name,id from opportunities) from account where CreatedDAte =Today';
//system.debug('sum'+query);
return Database.getQueryLocator(query);
}
public void execute(Database.BatchableContext bc, List<sObject> scope)
{
// AggregateResult[] gr =[SELECT SUM(Amount) optyamt FROM Opportunity];
list<account> accountupdate =new list<account>();
for(account acc:accountupdate)
{
if(Opportunity.AccountId == Account.Id)
{
AggregateResult[] gr= [SELECT SUM(Amount) optyamt FROM Opportunity];
system.debug('value:'+gr);
for(Opportunity opp:gr)
{
Account accm =new Account();
sum =(Decimal)opp.get(optyamt);
accm.Pipeline__c =sum;
}
}
update(acc);
}
}
public void finish(Database.BatchableContext bc) {
System.debug(logginglevel.FINEST, 'FINISHED BATCHING.');
}
}
Following error received in my batch class Variable does not exist: optyamt
Thanks Pb