function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Suman BonthalaSuman Bonthala 

After undelete trigger on opportunity

//Opportunity is parent and Customer Project is chlid 
trigger trgcpundelete on Opportunity(after undelete)
 {
     set<id>oppid= new set<id>();
     if(trigger.isafter&&trigger.isundelete)
      {
         for(Opportunity o : trigger.new)
         {
          oppid.add(o.id);
         }
      }  
     list <Customer_Project__c> cplist = [select id,name,Opp_relation__c from Customer_Project__c where isdeleted=true and Opp_relation__c IN:oppid];
     undelete cplist;
}

//if i undelete opportunity the child records doesnot undelete
Best Answer chosen by Suman Bonthala
Maharajan CMaharajan C
Hi Suman,

Try this,

trigger trgcpundelete on Opportunity(after undelete)
 {
     set<id>oppid= new set<id>();
     if(trigger.isafter&&trigger.isundelete)
      {
         for(Opportunity o : trigger.new)
         {
          oppid.add(o.id);
         }
      }  
     list <Customer_Project__c> cplist = [select id,name,Opp_relation__c from Customer_Project__c where Opp_relation__c IN:oppid AND isDeleted = true ALL ROWS];
     
if(cplist .size()>0){
     undelete cplist;
}

}


Thanks,
Maharajan,C

All Answers

Maharajan CMaharajan C
Hi Suman,

Try this,

trigger trgcpundelete on Opportunity(after undelete)
 {
     set<id>oppid= new set<id>();
     if(trigger.isafter&&trigger.isundelete)
      {
         for(Opportunity o : trigger.new)
         {
          oppid.add(o.id);
         }
      }  
     list <Customer_Project__c> cplist = [select id,name,Opp_relation__c from Customer_Project__c where Opp_relation__c IN:oppid AND isDeleted = true ALL ROWS];
     
if(cplist .size()>0){
     undelete cplist;
}

}


Thanks,
Maharajan,C
This was selected as the best answer
Suman BonthalaSuman Bonthala
Hello Maharajan,C

Thanks for your reply it works finely,


From
SUMAN
with Regards