+ Start a Discussion
ranadheer reddy chaduvuranadheer reddy chaduvu 

How to convert the below trigger to batchclass

trigger preventingdeletion on Apple__c (before delete) {

  for(Apple__C a:[select id,name,(select id from Orange__r ) from Apple__C where id in:Trigger.oldmap.keyset()]){
   if(a.Orange__r!=null&&a.Orange__r.size()>0){
    Apple__c actualRecord = Trigger.oldMap.get(a.Id);
   actualRecord.adderror('dont delete');
   }
   }

}



The above trigger is to prevent the parentobjectrecord from deletion if there is any child exists ...Here my parent object is Apple__C,and my child object is Orange__C,,help me ..thanks
Ramu_SFDCRamu_SFDC
Use the approach explained in the below post

https://developer.salesforce.com/forums?id=906F000000094EaIAI