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

  • 2
    FYI, there is an upper limit of 1,000,000 characters in a class, which is the error you're seeing.
    – sfdcfox
    May 1, 2020 at 23:53

2 Answers 2


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.

  • Thanks Keith I will give it try, I want to use it for Profiles and Permissions deployments using api, will it work for it? May 1, 2020 at 19:49
  • 1
    @rahulgawale PermissionSet is included here github.com/financialforcedev/apex-mdapi/blob/master/apex-mdapi/… so most likely Profile and PermissionSet are supported. I don't think updating those is supported by the Tooling API.
    – Keith C
    May 1, 2020 at 20:16

I had the same problem with upgrading Apex Wrapper Salesforce Metadata API to the latest version , I could not generate apex class due to the wsdl file exceeds the 1 million character limit

After conducting some research, it appears that the primary workaround for the issue of large metadata file sizes is to either split the metadata into multiple smaller files or selectively extract only the necessary metadata types into a separate file. To facilitate this process, I created a Python tool that allows me to extract necessary metadata types and patch the resulting class with the latest API version on my local machine. Then, I can save it in a Salesforce org. You can extract the metadata types you select using my python tool on your local machine, the main features are listed below:

  • Feature 1: Extract the components selected from Salesforce Metadata
    wsdl file with the latest API version.
  • Feature 2: Generate extension mapping file, that is required for patching the apex class generated from wsdl file from feature 1.
  • Feature 3: Patch the apex class generated with the mapping file and generate unit tests.

You can find and utilize the tool from this GitHub repository.

  • 1
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – identigral
    Aug 19, 2023 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .