You need to sign in to do that
Don't have an account?
Ashu3006
Want to Delete the Account when Opty Status is closed/won
Hi All,
I have the requirment ,
i have one Account with Name "Test " and it has 10 Opportunities for that Account "Test" I need to allow to delete the Account "Test" record only if the all Opportunites status have closed/own.
And i am not getting how to develop the trigger .
Can u please help me out who toi build the Logic
Regards
Anu
try this
trigger checkOpps on Account (before delete) {
List <Id> AccIds = new List <Id>();
List <AggregateResult> ops=[Select AccountId, COUNT(Id) cn From Opportunity Where AccountId in :trigger.old And StageName<>'Closed Won' Group By AccountId];
if(ops!=null && ops.size() >0){
for(Account acc: trigger.old){
for(AggregateResult op:ops){
if(acc.Id == op.get('AccountId') && (Integer)op.get('cn') > 0)
acc.adderror('Open Opportunity exist.');
}
}
}
}