0

How to access MetadataService.cls and use it? I want to modify the picklist values and reading couple of post I could understand that using MetadataService.cls i can achieve it but i dont know where to get this MetadataService.cls and how to access it ....an tips please?

1

Basically, you need to create a service with it, recreate your metadata using this class' internal classes, and then tell it to call the Metadata API of your organization. This is the basic usage. But for your case, you would need to create the service, tell it to call your organization's Metadata API to read what you have in there, and then manipulate this information and call the API again to update what you want. It would be a little too long to explain exactly what to do in here (based on what you are trying to do).

There is a text about the use of this class in particular by Andrew Fawcett in his blog. It might be a little outdated, but he has written another text with a more updated version of this same subject. You can get to know the process with this first text.

Please refer also to this example on how to do some of the basic operations with the class. There are also good examples on how to read the result given by the API.

| improve this answer | |
  • Thanks Renato. I've created the class from the wsdl but now having an issue "Initial expression is of incorrect type, expected: MetadataAPIService.Metadata" need some advise on how to fix it for the below code: – Prabhu Sethupathy Nov 2 '15 at 15:23
  • List<MetadataAPIService.SaveResult> results = service.updateMetadata( new MetadataAPIService.Metadata[] { customField }); handleSaveResults(results[0]); – Prabhu Sethupathy Nov 2 '15 at 15:23
  • I don't know what it might be by looking into two lines of code, but it seems that you are trying to pass a list to a method that accepts a single MetadataAPIService.Metadata element. Just a question: you mentioned that you generated the class using the WSDL, but why? (since the MetadataService class in the FFLib repository (github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/…) is pretty much the same for every Salesforce organization)? – Renato Oliveira Nov 2 '15 at 15:52
  • Well, i wanted to know on how the class was created in the first place and hence my search led to creation of the class from metadata wsdl in apex. still if i compare the method definition "updateMetadata" in the url u had given and the one i had generated seems to be the same. yet the cause of the error is not clear to me – Prabhu Sethupathy Nov 2 '15 at 16:17

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.