You need to sign in to do that
Don't have an account?
Avinash Angasay
Dml Question
Delete those Accounts who have more than 2 opportunities
If anyone Can write query for it.....
I got problem While deleting Account...\
I have written code like below---
but when i want to delete account at the end then it will not get deleted it is saying that account have cases...what to do now...how to process it forward from here in code for deleting these account records who has opportunities grater than 2 with them.....
List<Account> aList = [Select Name,(Select Name from Opportunities) from Account];
List<Account> delAcc = new List<Account>();
for(Account a:alist)
{
if(a.Opportunities.size()>2)
{
system.debug(a.Opportunities.size());
delacc.add(a);
}
}
system.debug(delacc);
delete delacc;
}
If anyone Can write query for it.....
I got problem While deleting Account...\
I have written code like below---
but when i want to delete account at the end then it will not get deleted it is saying that account have cases...what to do now...how to process it forward from here in code for deleting these account records who has opportunities grater than 2 with them.....
List<Account> aList = [Select Name,(Select Name from Opportunities) from Account];
List<Account> delAcc = new List<Account>();
for(Account a:alist)
{
if(a.Opportunities.size()>2)
{
system.debug(a.Opportunities.size());
delacc.add(a);
}
}
system.debug(delacc);
delete delacc;
}
Hi Avinash,
Please use below code. Kindly mark as best answer if this resolves your issue.
All Answers
Can you confirm if there are any cases for the account do you want to delete them as well?
Thanks
Can you try by using below logic where we delete the cases first and then delete the Accounts.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,
Hi Avinash,
Please use below code. Kindly mark as best answer if this resolves your issue.