[SalesForce] Script Too Large Error While Generating Apex Classes Using Metadata WSDL

While trying to Generate MetadataService classes using the standard Metadata API WSDL from Salesforce, classes I got below error. I think it is related to the length of the Apex class as the lines of code in MetadataService class are more than 13K.

I downloaded the WSDL file from Setup -> API -> Generate Metadata WSDL

Error: Script too large: public class MetadataService { public class ReportTypeColumnTranslation { public Strin... at 3:14

enter image description here

Best Answer

When I've wanted to invoke this API from Apex in the past I have used this already generated and modified code:

Apex Wrapper Salesforce Metadata API

though it looks like it hasn't have much attention in recent years. It does support at least this version of the API:

Summer'16 v37.0 Metadata API

and probably v42.0 based on commit comments.

The list of changes it applies to make the API work from apex is listed here MetadataServicePatcher.cls line 28, though no mention of the class size limit being hit. But additions to the WSDL since v37/v42 may be causing that.

The Tooling API can be accessed via JSON REST calls so does not require any generated code to use. If the operation you want to invoke is present in that API, it is a lot easier to use.

Related Topic