0

I have a requirement where Cases closed over x amount of days should be removed from Salesforce. However, when deleting the Case, the subsequent e-mail messages and attachments linked to both e-mail messages or the Case record itself are also deleted, and this is what I wanted to prevent.

So far what I have tried was creating a before delete trigger on the Attachment object, adding it an error to the sObject. This works for "manual" deletions but gets bypassed when a Case is deleted (meaning the attachments are still being cascade deleted).

Does anyone have an idea of how can this be achieved?

Best regards and thank you in advance!

2
  • What about trigger on case?
    – kurunve
    Jan 18 at 11:44
  • Thanks for the suggestion @kurunve! I will try to place that on after deletion to undelete the child records and let you know if it worked! Jan 18 at 11:47
3

One workaround would be to convert your attachment to salesforce files. Salesforce files has the ability to get linked with multiple records. Even if case is being deleted, the files will be there if you had related with some other record.

In your case, while converting, you can link with case owner and the case record. ContentDocumentLink objects links the file and the record.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.