Skip to main content
New tool CRON Expression Builder — preview next run times before you schedule Apex. Open the builder →
A 3D data cube representing the fix for the Entity expansion limit exceeded error in Salesforce
DevOps

Fixing Entity Expansion Limit Exceeded in VS Code

Learn why the 'Entity expansion limit exceeded' error occurs during metadata retrieval and how to resolve it using configuration adjustments. We walk through the technical root cause and provide a definitive fix for your VS Code development workflow.

The short answer

The entity expansion limit error occurs when the Salesforce CLI XML parser exceeds its safety threshold of 1000 entity references during metadata retrievals. Developers can resolve it by isolating problematic metadata files, filtering components with .forceignore, and breaking retrievals into smaller, modular packages.

Key takeaways Inspect the Salesforce CLI output log in VS Code to locate the exact metadata file triggering the parser error. Use a .forceignore file to exclude large or non-essential metadata components like reports, dashboards, and legacy objects. Split broad package.xml files and large directories into smaller, feature-based modular folders. Adjust local Node.js environment settings like NODE_OPTIONS or contact Salesforce Support if corrupted metadata causes circular XML expansions.

Fixing Entity Expansion Limit Exceeded in VS Code

If you have been working with large Salesforce orgs or complex metadata structures, you have likely encountered the frustration of a failed retrieve operation in VS Code. The error Entity expansion limit exceeded: 1010 > 1000 is a classic bottleneck that arises when the XML parser encounters a metadata file with too many entities defined.

In this guide, we’ll dive deep into why this happens, how the Salesforce CLI interacts with XML parsing, and the precise steps you need to take to restore your development flow.

Understanding the Root Cause

At its core, this error is not a Salesforce governor limit in the traditional sense. It is an XML security configuration limit. The Salesforce CLI, which powers the Salesforce Extension Pack for VS Code, uses standard XML parsers to process metadata files. To prevent "XML External Entity" (XXE) attacks—a common vulnerability where attackers use specially crafted XML to exhaust server memory—these parsers enforce a strict limit on entity expansion.

When you retrieve metadata, you are pulling thousands of XML files. If any of those files contain an excessive number of entity references (typically those starting with &), the parser hits its hard-coded safety threshold of 1000. In Salesforce environments, this is often triggered by complex Custom Labels, large Permission Sets, or massive FlexiPages that contain dense, repetitive XML definitions.

Isolate the Problematic Metadata

Before adjusting settings, it is vital to determine if a specific file is corrupt or if your project configuration is simply too broad.

  1. Check the Output Logs: Open the 'Output' panel in VS Code (Ctrl+Shift+U) and select 'Salesforce CLI' from the dropdown. Look for the specific file path mentioned right before the error appears.
  2. Run Selective Retrievals: Instead of pulling your entire package.xml, try splitting your retrieval. If you are pulling all custom objects, try pulling only a subset.
  3. Validate XML Structure: If you identify a specific file (e.g., a massive Permissionset), open it in a text editor and look for repetitive blocks. While rarely a manual coding issue, automated tools or older migrations sometimes inject redundant XML entities that trigger the threshold.

Modifying the Environment Variables

The most effective way to address the Entity expansion limit exceeded error is to instruct the Salesforce CLI process to allow a larger threshold. Since the CLI runs as a Node.js process, we can pass specific environment flags to change how the underlying XML parser behaves.

The Solution for Windows (PowerShell)

If you are on Windows, you can temporarily increase the limit by setting an environment variable in your current terminal session before running your sfdx commands:

$env:NODE_OPTIONS = "--max-old-space-size=4096"
# Or specifically for entity expansion if using custom parsers
# Note: This is an OS-level override

However, note that the entity limit is often baked into the libxmljs or the specific XML engine used by the CLI. If the error persists, you are likely looking at a need to optimize the metadata bundle rather than just the parser settings.

Optimizing Your package.xml Strategy

If you are hitting 1010+ entities, your package.xml is likely too "heavy." Metadata retrieval is an expensive operation; pulling the entire org into a single local project is a bad architectural practice.

Let’s look at a modular approach:

  • Use Feature-Based Directories: Instead of one massive force-app, break your project into smaller folders.
  • Exclude Unnecessary Components: Use a .forceignore file to ensure you aren't pulling back generated files that have nothing to do with your current development task.

Example of a clean .forceignore file:

# Ignore standard report types or generated docs
**/reports/**
**/dashboards/**
# Ignore specifically large, problematic objects
**/objects/Legacy_Massive_Object__c.object-meta.xml

By ignoring files that hit the parser limit but are not required for your current feature development, you bypass the error entirely.

When to Contact Salesforce Support

If you have narrowed down the error to a standard metadata type (e.g., a standard Profile or PermissionSet that is natively large) and you cannot ignore it, you may be hitting a structural issue with your Org’s metadata.

If you receive this error even on a narrow retrieve of a single file, verify if that file has been corrupted during a deployment. Sometimes, circular entity references can cause the parser to spiral out of control. If the XML appears valid but still triggers the error, reach out to Salesforce Support with the file content, as there may be an internal issue with the metadata encoding in your sandbox.

Key Takeaways

  • Don't Panic: The 1010 > 1000 error is a security safeguard against XML expansion attacks, not a failure of your code.
  • Audit Your Scope: The most frequent cause is trying to retrieve too much metadata at once. Review your package.xml and ensure it is scoped to the current work item.
  • Use .forceignore: This is your best tool. Actively ignore large, non-essential metadata files to reduce the load on the parser.
  • Node.js Environment: If you are a power user, check your local Node.js environment variables, but prioritize splitting your metadata over hacking the parser limits.
  • Modularize: Transitioning to a modular development architecture prevents this error from recurring as your org grows.

Frequently asked questions

What causes the Entity expansion limit exceeded error in Salesforce VS Code?

The error occurs when an XML parser in the Salesforce CLI encounters more than 1000 entity references in a metadata file. This threshold is an XML security safeguard against XML External Entity (XXE) attacks, typically triggered by dense metadata files such as Custom Labels, Permission Sets, or FlexiPages.

How do you fix Entity expansion limit exceeded: 1010 > 1000 during metadata retrieval?

You can resolve this error by narrowing your retrieval scope instead of pulling an entire package.xml file. Isolate the offending file using the VS Code Salesforce CLI output log, and add non-essential large files to your .forceignore file.

When should you contact Salesforce Support for the entity expansion error?

Contact Salesforce Support if the error persists when retrieving a single, standard metadata file that cannot be ignored or edited, such as a native Profile or PermissionSet. This can indicate a corrupted deployment or an internal metadata encoding issue in the org.

Newsletter

One email every Tuesday

New guides, tool updates, and the release-note changes that break things.

No spam. Unsubscribe in one click.

Comments

Loading comments...

Leave a Comment