11

How can I get list of all workflow rules using apex? I want to retrieve names of all workflow rules using apex code.

5

I haven't done it myself, but I think you could call the metadata api from apex and than process the output.

http://www.salesforce.com/us/developer/docs/api_meta/Content/meta_workflow.htm

4
  • 4
    The metadata API returns zip files though, so even if you get the WSDL to be parsed into an apex class there's no way to really handle the replies as there's no API for working with zip files in apex. Sep 1 '12 at 19:57
  • Thanks @ca_peterson so I think there is no way to get list of workflows itself in apex. Thanks for your inputs
    – Manisha
    Sep 3 '12 at 16:27
  • In all fairness, my answer was a bit shortsighted, Adam's is more accurate. Sep 4 '12 at 15:17
  • 1
    Do also take a look at my answer, I have managed to get retrieve to work and unzip the results. The demo in the github repo shows layouts, however it is a small change to list and retrieve workflows. :-) Nov 10 '12 at 20:28
4

Unfortunately I believe you would need to use the Metadata API for this, which requires processing outside of Apex (from Heroku in Python/Ruby, for example). However, if there's a way to get this done from within Apex, I'll be really happy to learn about it!

2
  • I think I can call metadata API from Apex (WSDL Import and all ).. but is it good practice to do so ? please suggest.
    – Manisha
    Sep 1 '12 at 18:43
  • 4
    Accessing the Metadata API from within Apex is not supported out of the box, but some have tried (with apparently some success) to do this: boards.developerforce.com/t5/Apex-Code-Development/…
    – Adam
    Sep 1 '12 at 19:14
3

I've been successful in getting parts of the Metadata API working from Apex using the WSDL2Apex tool and a few tweaks! However the listMetadata operation in respect to Workflow does not quite return what you would expect. Take a look at this answer for more info. Hope this helps!

https://salesforce.stackexchange.com/a/2208/60

2
  • I've enhanced the Apex library referenced in the github repo, it now does a Metadata Retrieve. Meaning you can list the Workflows using listMetadata and then use retrieve on each to get the actual list of rules from within! The example given uses Layouts but you can easily change it to Workflow component types. Hope this helps! github.com/financialforcedev/apex-mdapi#metadata-retrieve-demo Oct 16 '12 at 0:30
  • that might help me too, thanks for the github code. Let me try and then I can contribute to the repo. Nov 10 '12 at 8:59

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.