Find your content:

Search form

You are here

How to Search Workflow Rules or Validation Rules etc in Apex i.e. Metadata Search via Apex?

 
Share

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)


Attribution to: Chirag Mehta

Possible Suggestion/Solution #1

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.


Attribution to: Greg Grinberg

Possible Suggestion/Solution #2

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.


Attribution to: Andrew Fawcett

Possible Suggestion/Solution #3

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


Attribution to: Forceguru
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/1614

My Block Status

My Block Content