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
Chamil MadusankaChamil Madusanka 

Invoke APEX class via workflow

Hi All,

 

Are there any approaches to invoke APEX class via workflow?

 

Thanks in Advance

ministe2003ministe2003

Not directly, you can run Apex class methods through a trigger though, so I suppose you could write a trigger which ran the methods you want, and have a workflow that makes a field update to some hidden checkbox, which would in turn fire the trigger and you could say if (checkbox is ticked) {run apex class methods}

sfdcfoxsfdcfox

As a clarification to the above comment, the procedure outlined above is correct. Create a custom field, and have a Workflow Field Update update the custom field. Code your trigger such that it checks for the presence of the updated value. When workflow field updates cause a record to change, triggers are reevaluated. During the trigger, you can call any Apex Classes you desire (except callout functions; use @future for that).

Chamil MadusankaChamil Madusanka

Hi all,

 

Thanks for your reply. I have come up with new issue after read your comments. According to your reply, we can invoke a APEX class via field update workflow action and trigger. Trigger can invoke a apex class. It is obvious. Then we can only use triggers for such an invokation. If we use both workflow and triggers to invoke a apex class, then I think it will be wasted of performance and run time. I want to clarify it.Any Comments?

ministe2003ministe2003

No I didnt say you can invoke apex through a field update, what I said was that you can invoke it by a trigger, so in order to fire the trigger you need some form of event like a field update.  There is no way to invoke apex directly from a workflow so this is just a possible workaround.

@DBohrisch@DBohrisch
Would it be possible to see a sample of how this would work... I already have the Opportunity Amount field(standard/currency) that I want the apex class to run when updated but as I am still pretty new to all of this I am not sure how to envoke the Class in the Trigger when the Opportunity Amount(standard/currency) field is updated?
Thank you in advance!