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
john98755john98755 

trigger on approval process

hi'
 when ever approver reject the approve i want delete the record how to achive this.
ManojjenaManojjena
Hi John,

I think you want to delete the record once approver Reject .If I am correct then you can achieve this by using below trigger .

Only thing is that you need to change the Approval_status Api as per your org and the pick list value for Reject .

So your approval action will update that records approval status as rejected then your trigger will collect the record and delete .
I have written code for opportunity object you need to replace  your object name 
 
trigger DeleteRejectedRecord on Opportunity (after update ){
  Set<Id>oppIdSet=new Set<Id>();
  for(Opportunity opp : Trigger.new ){
    if(Trigger.oldMap.get(opp.Id).Approval_Status__c !='Rejected'  && opp.Approval_Status__c =='Rejected' ){
	  oppIdSet.add(opp.Id);
	}
  }
  if(!oppIdSet.isEmpty()){
	  try{
		Delete [SELECT id FROM Oppportunity WHERE Id IN: oppIdSet];
	  }catch(DmlException de ){
		System.debug(de);
	  }
  }
}
Let me know if it helps 

Thanks 
Manoj