You need to sign in to do that
Don't have an account?
I want add One more Logic Like If Opportunity Stage = Closed Lost then Account Status should Be Lost. In the below Code. How to I Implement
Currently Logic is If a Account Contains two Opportunity if 1.Opportunity Stage is "Closed Won" and If I am Updating 2 Opportunity Stage = "Closed Lost" then it will Update Account Status = Customer.
I want add One more Logic Like If Opportunity Stage = Closed Lost then Account Status should Be Lost. In the below Code. How to I Implement
public static void AfterListUpdateHandler(List<Opportunity> newOpps){
Set<Id> accIds = new Set<Id>();
Set<Account> acclists = new Set<Account>();
for(Opportunity opp : newOpps){
if(opp.StageName == STAGE_CLOSED_LOST){
accIds.add(opp.AccountId);
}
}
System.debug('OppListStage1 ::>'+accIds);
Opportunity [] OppListStage = [SELECT Id,StageName,AccountId FROM Opportunity WHERE AccountId IN: accIds AND StageName =: STAGE_CLOSED_WON];
System.debug('OppListStage2 ::>'+OppListStage);
if(OppListStage.size()>0){
for(Opportunity op : OppListStage){
Account acc = new Account();
acc.Id = op.AccountId;
acc.Account_Status__c = STATUS_CHURNED_CUST;
acclists.add(acc);
}
if(checkRecursive.runOnce()){
update new List<Account>(acclists);
System.debug('opp1 ::>acclists'+acclists);
}
}
}
I want add One more Logic Like If Opportunity Stage = Closed Lost then Account Status should Be Lost. In the below Code. How to I Implement
public static void AfterListUpdateHandler(List<Opportunity> newOpps){
Set<Id> accIds = new Set<Id>();
Set<Account> acclists = new Set<Account>();
for(Opportunity opp : newOpps){
if(opp.StageName == STAGE_CLOSED_LOST){
accIds.add(opp.AccountId);
}
}
System.debug('OppListStage1 ::>'+accIds);
Opportunity [] OppListStage = [SELECT Id,StageName,AccountId FROM Opportunity WHERE AccountId IN: accIds AND StageName =: STAGE_CLOSED_WON];
System.debug('OppListStage2 ::>'+OppListStage);
if(OppListStage.size()>0){
for(Opportunity op : OppListStage){
Account acc = new Account();
acc.Id = op.AccountId;
acc.Account_Status__c = STATUS_CHURNED_CUST;
acclists.add(acc);
}
if(checkRecursive.runOnce()){
update new List<Account>(acclists);
System.debug('opp1 ::>acclists'+acclists);
}
}
}
All Answers