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
S_2013S_2013 

Initiate Apex code at a future date?

Hi,

I need to clone an opportunity at a particular future date. I need this cloning to happen automatically (no button click etc. ) on a scheduled date (which is a date field on the opportunity itself. Is schedulable job the only option? Can I manage the initiation with WF?

Regards

Sankalita

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9
A field update can always intiate a Update Trigger. You have to write a update trigger along with WF which will do the cloning.

Any update action on opportunity will fire trigger , you can tap that event from trigger to execute apex code

All Answers

Avidev9Avidev9
You can use WF time triggers to update a field on Opportunity say a checkbox.
Now you have to write a trigger that will check the value of this checkbox and clone your record.

Make sure that you hide this field from users
S_2013S_2013

Hi Avi,

Thank you for your reply.

What I am still in doubt with is that, only the following options are available when executing a time dependent or normal WF: Field Update, Outbound Message, Email Alert and Task, and none of these options can actually initiate apex code. The cloning has to begin automatically and without user intervention as I mentioned, so I will be needing Apex as per my knowledge. Please correct if I am wrong.

 

Avidev9Avidev9
A field update can always intiate a Update Trigger. You have to write a update trigger along with WF which will do the cloning.

Any update action on opportunity will fire trigger , you can tap that event from trigger to execute apex code
This was selected as the best answer
S_2013S_2013
Got the idea.
Thanks so much:)
have a nice day