[SalesForce] Error when reading metadata: INVALID_TYPE: This type of metadata is not available for this organization

I am trying to get a list of all metadata objects with the given name. However, the code below fails:

connection.readMetadata("ApexClass", new String[] {"SampleDeployClass"});

with this error:

Exception in thread "main" com.sforce.ws.SoapFaultException: INVALID_TYPE: This type of metadata is not available for this organization

Using connection.listMetadata() I am able to confirm that SampleDeployClass exists. I'm using a DE org, and the user has the Modify all data permission.

Is this something expexted (couldn't find it in the docs)? If yes, how am I able to confirm that a set of metadata objects already exists (other than retrieve())?

UPDATE 1:

Seems like renameMetadata() doesn't work with ApexClasses either. Is it maybe a restriction in the API which prevents anyone from changing Apex code?

UPDATE 2:

Nor does it work using JSForce, so it's not something related to the client code.

Best Answer

I think you need to use Tooling API instead.

I'm using JSForce for this.

connection.tooling.sobject('ApexClass').retrieve('01p7R000007Axk8QAC', (error, result) => {
   
});
Related Topic