You need to sign in to do that
Don't have an account?
suji srinivasan
Batch Apex update issue
Hi,
I need to update
1.account rating as client customer if opportunity = last 2 years & closed opportunity
2.account rating as prospect if opportunity = last 3 to 5 years & open opportunity.
3. for last 2 years if account have two opportunity and both are open it should get update as prospect.
4.some accounts have two opportunities one as open and another as closed and its updating it as prospect if it has open opportunity for recent year it should get update as client customer
can anyone guide me .
global class AccountOptyBatchclass implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext bc) {
list<Id> accopty = new list<Id>();
string query='select ID,Name,Rating,(select Id,AccountId,stageName,CloseDate From Opportunities) from Account';
return Database.getQueryLocator(query);
}
global Void execute(Database.BatchableContext bc, List<Account> Scope){
list<Account> accopty = new list<account>();
system.debug('query'+scope);
for(Account a :Scope){
for(Opportunity o: a.Opportunities){
date dt = system.today().adddays(-1825);
date ty = system.today().adddays(-730);
system.debug ('dt'+dt);
system.debug ('ty'+ty);
if((o.CloseDate >=ty) && (o.StageName =='Won-Work In Progress' || o.StageName =='Closed Won' || o.StageName =='Delivered')) {
a.rating='Client - Customer';
accopty.add(a) ;
system.debug(' Last2yearsCloseDate'+a.rating) ;
}
else if( (o.CloseDate >=ty) && (o.StageName =='Shaping' || o.StageName =='Proposal Submitted' || o.StageName =='Decision' || o.StageName =='Engagement' )){
//if ((o.StageName !='Won-Work In Progress' || o.StageName !='Closed Won' || o.StageName !='Delivered' )&&(o.CloseDate < ty)){
a.rating='prospect';
accopty.add(a) ;
system.debug(' Last3to5yearsCloseDate'+a.rating) ; //}
}
}}
update accopty ;
}
global void finish(Database.BatchableContext bc){
}
}
Thanks in Advance
I need to update
1.account rating as client customer if opportunity = last 2 years & closed opportunity
2.account rating as prospect if opportunity = last 3 to 5 years & open opportunity.
3. for last 2 years if account have two opportunity and both are open it should get update as prospect.
4.some accounts have two opportunities one as open and another as closed and its updating it as prospect if it has open opportunity for recent year it should get update as client customer
can anyone guide me .
global class AccountOptyBatchclass implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext bc) {
list<Id> accopty = new list<Id>();
string query='select ID,Name,Rating,(select Id,AccountId,stageName,CloseDate From Opportunities) from Account';
return Database.getQueryLocator(query);
}
global Void execute(Database.BatchableContext bc, List<Account> Scope){
list<Account> accopty = new list<account>();
system.debug('query'+scope);
for(Account a :Scope){
for(Opportunity o: a.Opportunities){
date dt = system.today().adddays(-1825);
date ty = system.today().adddays(-730);
system.debug ('dt'+dt);
system.debug ('ty'+ty);
if((o.CloseDate >=ty) && (o.StageName =='Won-Work In Progress' || o.StageName =='Closed Won' || o.StageName =='Delivered')) {
a.rating='Client - Customer';
accopty.add(a) ;
system.debug(' Last2yearsCloseDate'+a.rating) ;
}
else if( (o.CloseDate >=ty) && (o.StageName =='Shaping' || o.StageName =='Proposal Submitted' || o.StageName =='Decision' || o.StageName =='Engagement' )){
//if ((o.StageName !='Won-Work In Progress' || o.StageName !='Closed Won' || o.StageName !='Delivered' )&&(o.CloseDate < ty)){
a.rating='prospect';
accopty.add(a) ;
system.debug(' Last3to5yearsCloseDate'+a.rating) ; //}
}
}}
update accopty ;
}
global void finish(Database.BatchableContext bc){
}
}
Thanks in Advance
All Answers