When the Opportunity is deleted then delete accounts and contacts of that opportunity

Trigger DeleteTrigger on Opportunity(after delete){
        Map<Id,Opportunity> setopp=new Map<Id,Opportunity>();
        for(Opportunity opp:Trigger.old){
         setopp.put(opp.AccountId,opp);
                 
        }
        List<Account> deletelist=new List<Account>();
        List<Account> accountlist=[select Id,Name  from Account where Id in:setopp.keyset()];
        for(Account acc:accountlist){
            deletelist.add(acc);
           
        }
             
    if(!deletelist.isEmpty() && deletelist.size()>0){
       
            delete  deletelist;
    }
   
       
    }

Comments

  1. nice post iam also write like this you check
    you can learn a Advantages of my Domain in Salesforce and how to use my domain in salesforce org step by step guid https://www.salesforcekeeda.com/2018/10/how-to-use-my-domain-in-salesforce-best.html

    ReplyDelete

Post a Comment