I need to write a trigger on Case object where I need to delete the placeholder records and relate the case to existing records. I need to prepare the list of placeholder in before context and delete the same list in after context. What would be best approach for this? Can I use static list and delete it in after context? Please advise.
Ex. I have a related lookup filled out with a placeholder record. when the case is closed as it turns out the case should be related to an existing record, so I need to delete the placeholder record. As a best practice, I cannot delete the related placeholder in before context but I need to update the case in before. Let me know if this clarifies the question.
Example - When Case 1 is inserted, Case 1 is related to RecordA(Placeholder)
When Closed after review Case 1 need to be related to RecordB(Existing record)
Before Context Update Case 1 => RecordB Make a tobeDeleted list with recordA -- I made this list static
After Context If tobeDeleted != Empty, delete tobeDeleted
Is this the correct approach? Or is there any better way?