11

Recently I'm working on building something for developers/administrators - a handy 100% force.com app allowing to search metadata. Currently this app allows you to quickly search (from sidebar) custom code components (Pages, Apex Classes, Components and Apex Triggers).

Now I'm trying to add feature to search workflows or validations or email templates or fields etc, but stuck with some apex limitations. There's no APEX or direct api (methods) to search(query) above components. What are the options here for me?

  1. Use Metadata WSDL, parse it as apex class and then use that to retrieve/search the necessary component list ??
  2. Use Metadata REST API ??

  3. Crawler in VF using JS (just a wild hacky thought, not even sure if this's possible)

  • 3
    This isn't a direct answer to your question - the metadata API answers are correct - but for anyone looking at this question and wondering how to do it themselves without using the API directly, the easiest way is to use the Force.com IDE, download all selectable metadata, and then do a full-text search (ctrl-H). I've worked with several people who did not know/realize this. – jkraybill Sep 25 '12 at 8:50
  • @jkraybill - Force.com IDE is obvious choice for developers, but not for admins. Also when you are moving or in remote location (ie when you dont have IDE on the machine) then we need some native (force.com) way of doing it. That's what I'm trying to build :) – Chirag Mehta Sep 25 '12 at 13:27
  • Sound great, I support it! We need more tooling in general, I look forward to seeing your app. A native full-text metadata search would be great. – jkraybill Sep 25 '12 at 13:35
  • yes that's what I'm tyring upto. – Chirag Mehta Sep 25 '12 at 15:35
  • When clients have wanted to do workflow cleanups one approach that has been fruitful has been to export the data into Eclipse and use the raw metadata to generate a CSV that includes the workflow rules. You can then email the CSV to the appropriate admins. – Ralph Callaway Nov 6 '12 at 15:41
8

UPDATE: 11th Nov, I discovered the WorkflowRule (as apposed to the Workflow) metadata type! Combined with the ValidationRule metadata type. This means that the Metadata listMetadata API call now returns exactly the two lists you need to implement your search tool.

This will allow you to list the Validation Rules and Workflow Rules from Apex.

MetadataService.MetadataPort service = MetadataServiceExamples.createService();     
List<MetadataService.ListMetadataQuery> queries = new List<MetadataService.ListMetadataQuery>();        
MetadataService.ListMetadataQuery queryWorkflow = new MetadataService.ListMetadataQuery();
queryWorkflow.type_x = 'WorkflowRule';
queries.add(queryWorkflow);     
MetadataService.ListMetadataQuery queryValidationRule = new MetadataService.ListMetadataQuery();
queryValidationRule.type_x = 'ValidationRule';
queries.add(queryValidationRule);           
MetadataService.FileProperties[] fileProperties = service.listMetadata(queries, 25);
for(MetadataService.FileProperties fileProperty : fileProperties)
    System.debug(fileProperty.fullName);

For more information and the MetadataService and MetadataServiceExamples class used in the above code. Please take a look at this Github repo and Readme file.

  • let me check this and get back to you, anyhow thanks a lot for such detailed post. – Chirag Mehta Oct 18 '12 at 5:25
  • Your welcome Chirag! Hope you get it sorted. If you do or need a hand, happy to help! Maybe we can build a small sample and commit to the repo as well? – Andrew Fawcett Oct 23 '12 at 7:11
  • Sure. can you please drop me an email at jain.chirag[at]gmail.com – Chirag Mehta Oct 23 '12 at 12:00
  • Just updated my answer, while exploring the 'describeMetadata' Metadata API, I discovered that you can ask the listMetadata API for WorkflowRule's! The snippet above should now be spot on for what you've asked for. Have fun! – Andrew Fawcett Nov 11 '12 at 18:31
  • Your very welcome! Lots of possibilities lie ahead with this. Glad to see this seems to have answered your question... ;-) – Andrew Fawcett Nov 20 '12 at 9:08
0

Not sure for others but for Email Templates you can use

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_emailtemplate.htm#topic-title

  • yes I realized the same after posting above, that emailtemplates too are available in a object/table form, so soql will help here. Thanks for your answer. However my major conern is on how to search the workflows and validation rules. – Chirag Mehta Sep 25 '12 at 8:26
0

I would go with the metadata REST api over the SOAP one as it will be significantly easier to deal with in apex and salesforce will be adding all the metadata components that are exposed in the SOAP api as time passes.

  • yes metadata REST API is obvious choice even for me :) – Chirag Mehta Sep 25 '12 at 8:27
  • I'm not sure I understood your question then. – Greg Grinberg Sep 25 '12 at 17:59
  • what part is confusing? as said in main post, I'm trying to develop visualforce page which allows to search for metadata (pages, classes...validation rules, workflows etc).. So to search pages, classes.. I had to do simple soql on their respective objects. But for validation rules or workflows there's no such object available, so the only way to get the list of validation rules or wf is to use metadata api (via REST or SOAP). Hope that clears your confusion. – Chirag Mehta Sep 26 '12 at 3:42
  • Yep I would love to use the REST API as well. Unfortunately the REST API is read only in Pilot. And I've been told the GA read/write version is someway away sadly. So it depends on how long your prepared to wait I guess. – Andrew Fawcett Oct 12 '12 at 21:13
  • That's sad thing, are you sure its in Pilot yet? – Chirag Mehta Oct 18 '12 at 5:25

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.