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
AmitSahuAmitSahu 

Need to Delete the record on which I am operating

Hi All,

 

I would need help on a solution to delete the record on which I am operating.

 

Example : If I am inserting a record in Case object (Using triggers here) . Once the case is inserted I need to delete that.

 

Any thoughts ?

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

You can't delete the record that is being inserted any more - this used to be allowed but changed some time around winter 11 (from memory) an now throws an exception.  Thus you either need to change the API version of the trigger to one that allows that change or carry out an asynchronous delete.  

All Answers

Damien_Damien_

You have a trigger, on case, and you want to delete the record that the trigger is executing on?

bob_buzzardbob_buzzard

You can't delete the record that is being inserted any more - this used to be allowed but changed some time around winter 11 (from memory) an now throws an exception.  Thus you either need to change the API version of the trigger to one that allows that change or carry out an asynchronous delete.  

This was selected as the best answer
AmitSahuAmitSahu
Thanks bob . Are you saying that I could use @future method?
bob_buzzardbob_buzzard

You could, but there are limits on how many of these you can fire in a 24 hour period - 200 per full Salesforce/ full Platform or Force.com One App license.

 

Another way would be to mark the record for deletion and then have some scheduled apex clean up on a regular basis.

AmitSahuAmitSahu
Yes true. The limitations is there. What I am currently doing is storing the id of the record in a new object and on insert of that record am deleting the parent record based on the id . Deleting all records from the new object in a nightly job.