[SalesForce] How List all the Properties of Validation Rules through Metadata Api

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';
queries.add(queryValidationRule);                    
MetadataService.FileProperties[] fileProperties = service.listMetadata(queries, 25);

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

Best Answer

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! :)

Related Topic