Trigger to permanently delete records salesforce

You are currently viewing Trigger to permanently delete records salesforce
Trigger to permanently delete record in salesforce apex

Once we delete any record from salesforce object that record get stored in salesforce recycle bin for next 15 days. If you want to permanently delete that record you have to delete it from recycle bin. There are some ways to prevent this case such as you can hard delete record using hard delete option.

You can locate to the recycle bin in salesforce classic by – https://your-org/search/UndeletePage

In this blog you will learn how to write trigger to automatically delete record from recycle bin. 

Trigger to automatically delete records from recycle bin

				
					trigger DeleteRecFromRecycleBin on Account (after delete) {
    for(Account deletedAcc : Trigger.old) {
        Database.emptyRecycleBin(Trigger.old);
    }   
}
				
			

Here we have written trigger on Account which will get executed after deleting one or more records.

Here we are using emptyRecycleBin method which can take sObject or List<sObjects> as an argument.

Leave a Reply