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
A.V.A.V. 

Executing Apex Triggers Asynchronously

What is the best appoarch to execute Apex code asynchronously?

I have a scenario where I am copying attachments (with Apex Code) as a result of an Account record update. I would like to perform this in an asynchronous manner so that the UI response is not slowed when processing large attachments...

One way I can think of is with Workflow rules. I have not tried it yet, but I suppose it is possible to specify a time delayed workflow that would update some flag field, which in turn will trigger the code that will execute the code.

Is there a better way to do this?  Once again, my objective is to kick off some code in a trigger but not having to wait for it to complete...

Thank you.
SuperfellSuperfell
Expose your apexCode as a webService, and use the Workflow Outbound Messaging feature. You'll just need a small endpoint hosted somewhere that takes the OM message and turns around and make the WS call back to your apex code.