Variable does not exist: meaning and how to fix it

Apex runtime Checked against the official docs on Source: SOAP API Developer Guide: Core Data Types, StatusCode

Quick answer

Variable does not exist: An Apex compile error: the code uses a variable or field that does not exist in the org, is misspelled, or is not visible to the code (for example a field missing in the target org). Start with: Check the spelling and the API name of the field or variable.

Typical message: Variable does not exist: Region__c

Cause

An Apex compile error: the code uses a variable or field that does not exist in the org, is misspelled, or is not visible to the code (for example a field missing in the target org).

How to fix Variable does not exist

  1. Check the spelling and the API name of the field or variable.
  2. If it is a custom field, confirm it exists in the org you are saving or deploying to.
  3. When deploying, include the field in the deployment or deploy it first.

Have a different message? Paste it into the error decoder, which matches it against 45 common Salesforce errors in your browser.

Frequently asked questions

What does Variable does not exist mean in Salesforce?

An Apex compile error: the code uses a variable or field that does not exist in the org, is misspelled, or is not visible to the code (for example a field missing in the target org).

How do I fix Variable does not exist?

1. Check the spelling and the API name of the field or variable. 2. If it is a custom field, confirm it exists in the org you are saving or deploying to. 3. When deploying, include the field in the deployment or deploy it first.

More Apex runtime errors

SFDX Talk is unofficial documentation. It is not affiliated with, endorsed by, or sponsored by Salesforce, Inc. Message text varies slightly by release and context, so confirm against the official page before relying on it.