Is there a way to fetch the meta.xml file via tooling api query? The meta.xml looks like this for apex class:

<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">

and for pages it looks like this :

<?xml version="1.0" encoding="UTF-8"?>
<ApexPage xmlns="http://soap.sforce.com/2006/04/metadata">

How can I fetch them via query ? Or which API should I use to fetch it.


You can retrieve equivalent information from the Tooling API, but if what you want is the on-disk format Metadata API source code, just perform a retrieve with the Metadata API.

You'd do that by calling retrieve() to retrieve a ZIP file, supplying a package manifest (package.xml file or the data-structure equivalent). You can then unpack the ZIP file to get the same -meta.xml file that you would when using any Salesforce IDE.

Since there are many extant Metadata API clients (Salesforce DX, Workbench, various IDEs...) you may not even need to write any code to do this, depending on your specific use case.

Tooling API

Review the Tooling API object reference to identify the location of the relevant data points in Tooling API response objects. The above link is for ApexPage, the Visualforce page entity; you'll note that that object contains the properties ApiVersion, IsAvailableInTouch, IsConfirmationTokenRequired, and MasterLabel, just like the -meta.xml file does. You can include these points in your Tooling API queries against the ApexPage object.

You can reconstruct the Metadata API-format XML source from this data, but it's easier just to get it from the Metadata API in the first place unless you only need the data, not the XML file.

| improve this answer | |
  • You can retrieve equivalent information from the Tooling API how can I achieve this? Is there a query? – Nagendra Singh Apr 21 '19 at 12:32
  • @NagendraSingh I've expanded my answer. No, there isn't a single query that will return that specific XML, but the contained data points should be available through the Tooling API at least in many cases (I don't know if coverage is exactly 1:1). – David Reed Apr 21 '19 at 12:38
  • @NagendraSingh The Tooling API only has enough functionality as needed for IDE Development. This means many metadata types wouldn't be available for use compared to the Metadata API. As David says, you'll need to use the right tool for the job. – sfdcfox Apr 21 '19 at 12:48
  • Thanks, yes understood, I was using tooling api for most of my operations, such as generating symbol table etc. But now I think I have to check metadata api too. – Nagendra Singh Apr 21 '19 at 12:52

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.