You need to sign in to do that
Don't have an account?
Using the metadata API from within Apex code
Hi all.
I'm aware of the metadata API and understand how to use it from code external to Salesforce, in Java or C# for example. But what I really need is to use this API from within Apex code in a custom controller. I want to be able to set up some page layouts in the browser, then query the fields on them and whether they're required or not from within my Apex code.
I could generate a SOAP client for the metadata API in Apex code and use that, but I'd really like to aovid going outside just to get back in again. For a start, the tool under Setup that consumes a WSDL and generates an Apec class pukes on the metadata WSDL file (Error: Class name 'Metadata' already in use. Please edit WSDL to remove repeated names). So that already seems a bad approach.
Is there an internal way to access this API?
Thanks in advance,
Eliot Stock.
Hi,
You can try exploring SCHEMA Class in Apex for this purpose.
It does provide lot of useful describe information, but haven't validated myself whether it provides meta data level info (page layout or not).
I have used Schema class for retrieving RECORD TYPE of a given object from the system.
- Satgur
Looks like this is the best that will give me:
Schema.DescribeSObjectResult[getKeyPrefix=a00;getLabel=CustomProject;getLabelPlural=CustomProjects;getLocalName=CustomProject__c;getName=CustomProject__c;getSObjectType=CustomProject__c;isAccessible=true;isCreateable=true;isCustom=true;isDeletable=true;isDeprecated=false;isDeprecatedAndHidden=false;isMergeable=false;isQueryable=true;isSearchable=true;isUndeletable=true;isUpdateable=true;]
Nothing on page layouts.
While you can do Schema describe calls (and object and field describes), you can not get the meta data on page layouts from within Apex directly (I want this too for an idea I'm toying with).
The SOAP client won't work either. If I'm not mistaken you can call the salesforce servers from the server itself.
... I really should proofread before hitting 'Post' ..
Yes, that's what I meant.
If you are having the error mentioned by you then edit your Metadata.wsdl file and go to
<service name="MetadataService">
<documentation>Manage your Salesforce.com metadata</documentation>
<port binding="tns:MetadataBinding" name="Metadata">
this section, then simply change the name in port binding tag to different one. It will solve the problem.
NOTE ==> If it gives you another error regarding "delete" or "update" then change their names too.