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
Erik BurtonErik Burton 

Can invocable apex or flow delete the object passed to it from process builder?

We use Email-to-Case to create and update cases from customer emails.  Currently, whenever a reply comes in to an old closed case, it always reopens the old case (if the email has the case's RefID in it).  Instead, we'd like to be able to use business rules to determine whether an inbound email referencing an old case reopens that case or creates a new case.

To do this, I'm planning to use process builder to apply business rules to newly created incoming EmailMessage objects.  If it detects a reply that should be linked to a new case, rather than reopening the old case, it would pass that EmailMessage to an invocable apex class (or possibly a flow), which would clone that incoming email, create a new case, and link the two together.  All of that seems pretty straightforward.

However, I would also like the invocable apex (or flow) to be able to delete the original email message, so it is not associated with the original parent case.  Is that also possible?  Or is that initiating object inaccessible (or undeletable) by the invoked code?

Thanks for your help!
Raj VakatiRaj Vakati
I can say yes .. follow this steps 
  • Create flow to delete the record ( you can use Record Delete element from the flow ) 
  • Invoke this flow from the process builder