How can I get list of all workflow rules using apex? I want to retrieve names of all workflow rules using apex code.
3 Answers
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
-
4The 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. Commented Sep 1, 2012 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– ManishaCommented Sep 3, 2012 at 16:27
-
In all fairness, my answer was a bit shortsighted, Adam's is more accurate. Commented Sep 4, 2012 at 15:17
-
1Do 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. :-) Commented Nov 10, 2012 at 20:28
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!
-
I think I can call metadata API from Apex (WSDL Import and all ).. but is it good practice to do so ? please suggest.– ManishaCommented Sep 1, 2012 at 18:43
-
4Accessing 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/…– AdamCommented Sep 1, 2012 at 19:14
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!
-
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 Commented Oct 16, 2012 at 0:30
-
that might help me too, thanks for the github code. Let me try and then I can contribute to the repo. Commented Nov 10, 2012 at 8:59