I need to list all the Properties of Validation Rule like Status, Description, Error Message, Error Formula inside the Salesforce through Metadata API.

As per my understanding, we can retrieve only fullName property via Metadata API(using 'listmetadata' call). If my understanding is wrong and we can get all the properties, I would request you to provide me the information which can help me to implement this in my code.

Here is the code which I am using currently:

MetadataService.MetadataPort service = createService();     
List<MetadataService.ListMetadataQuery> queries = new List<MetadataService.ListMetadataQuery>();                  
MetadataService.ListMetadataQuery queryValidationRule = new MetadataService.ListMetadataQuery();
queryValidationRule.type_x = 'ValidationRule';
MetadataService.FileProperties[] fileProperties = service.listMetadata(queries, 25);

for(MetadataService.FileProperties fileProperty : fileProperties) {
    system.debug('Validation Rule Name'+fileProperty.fullName);

1 Answer 1


You appear to be using the Metadata API Apex wrapper, so my answer mainly revolves around the use of that to accomplish what you need. Though the answer (currently API wise) will be the same on or off platform and that is to use the 'retrieve' Metadata API call listing the Validation Rules you want.

Apex Metadata Wrapper: You have to use the 'retrieve' call for this, unfortunately for Apex this presents a small challenge. Since it returns a Zip file with the information you require contained within, in XML form. If your happy to utilise a bit of client processing, you can still resolve this natively on the platform. As per the Retrieve Demo from the Apex Metadata wrapper library you using, study this example to see how it works.

enter image description here

(ignore the incorrectly titled section above, the sample originally pulled only Layouts and I've yet to fix the section title in the repo)

Hope this helps and welcome to StackExchange! :)

  • Thanks Andrew, I am using your metadata retrive controller to get the zip file of the metadata. Am I allowed to de searialize tha metadata zip file into objects so that I can use it in apex as an another class. Thanks in advance.
    – I.S.K
    Commented Jan 31, 2013 at 6:38
  • Yes that can be done, just change the receiveMetadataZipFile handler to store in your custom object what it receives rather than put it in viewstate as the demo did for simplicity. Commented Jan 31, 2013 at 16:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .