Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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);
}           
share|improve this question

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
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 Jan 31 '13 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. –  Andrew Fawcett Jan 31 '13 at 16:54
    
Thanks Andrew. That works fine. –  I.S.K Feb 4 '13 at 4:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.