# Salesforce Error Message Decoder

> A curated reference of 45 common Salesforce errors with the cause and fix steps for each. Status codes were checked against the official StatusCode list on 2026-11-17; causes and fixes are SFDX Talk's own advice.

Source: [SOAP API Developer Guide: Core Data Types, StatusCode](https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_calls_concepts_core_data_objects.htm)
Interactive decoder: https://sfdxtalk.com/tools/salesforce-error-decoder/

An error has a code (such as REQUIRED_FIELD_MISSING or System.NullPointerException) and a message. Look up the code first. Wrapper errors such as System.DmlException and CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY name the real cause later in the text.

## Data and DML

### FIELD_CUSTOM_VALIDATION_EXCEPTION

Typical message: `FIELD_CUSTOM_VALIDATION_EXCEPTION, Amount must be positive: [Amount]`

Cause: A validation rule on the object evaluated to true, so Salesforce blocked the save. The text after the code is the error message of that rule, and the field in brackets is where the rule shows the error.

Fix:
1. Read the message after the code: it is the rule's own error message.
2. In Setup, open Object Manager, the object, then Validation Rules, and find the rule with that message.
3. Fix the data so the rule passes, or correct the rule formula if it is wrong.
4. In Apex, catch DmlException and use getDmlMessage(0) to show the rule message to the user.

### REQUIRED_FIELD_MISSING

Typical message: `REQUIRED_FIELD_MISSING, Required fields are missing: [Name]`

Cause: The record is missing a value for a field that is required by the platform (such as Name), by the field definition, or by the page layout used through the API call.

Fix:
1. Look at the field names in brackets and set a value for each one before the insert or update.
2. For a custom field, check whether the field itself is marked required in its definition.
3. In a data load, check the CSV column mapping and blank cells.

```apex
insert new Contact(FirstName = 'Ada'); // LastName is required
```

### DUPLICATE_VALUE

Typical message: `DUPLICATE_VALUE, duplicate value found: External_Id__c duplicates value on record with id: 001...`

Cause: A field marked unique (or an external ID with unique values) already holds the value you are saving on another record.

Fix:
1. Use the record ID in the message to open the existing record.
2. Update that record instead of inserting a new one, or change the value.
3. In Apex or a data load, use upsert on the external ID field to update-or-insert.

### DUPLICATES_DETECTED

Typical message: `DUPLICATES_DETECTED, Use one of these records?`

Cause: An active duplicate rule with the Block action found a likely duplicate of the record you are saving. The Allow action with an alert can be overridden by the caller.

Fix:
1. Open the matching records named in the error and update one of them instead.
2. If the rule action is Allow with an alert, saving through Apex can set the duplicate rule header to allow the save.
3. Review the matching rule if it blocks legitimate records.

```apex
Database.DMLOptions dml = new Database.DMLOptions();
dml.DuplicateRuleHeader.allowSave = true;
Database.insert(acc, dml);
```

### STRING_TOO_LONG

Typical message: `STRING_TOO_LONG, Name: data value too large: ... (max length=80)`

Cause: A text value is longer than the maximum length of its field. The message names the field and the maximum length.

Fix:
1. Shorten the value, or use the field's max length from the message as the limit.
2. If the data legitimately needs more room, move it to a Long Text Area field.
3. In Apex, truncate deliberately with String.abbreviate or substring before saving.

### INVALID_CROSS_REFERENCE_KEY

Typical message: `INVALID_CROSS_REFERENCE_KEY, invalid cross reference id`

Cause: An ID in a lookup or master-detail field does not point to a usable record: it does not exist in this org, belongs to the wrong object, was deleted, or came from another org (for example a production ID used in a sandbox).

Fix:
1. Check that the ID exists in this org with a SOQL query on the target object.
2. Check the ID prefix matches the object the lookup expects.
3. After a data migration or sandbox refresh, remap IDs instead of copying them.

### ENTITY_IS_DELETED

Typical message: `ENTITY_IS_DELETED, entity is deleted`

Cause: The operation referenced a record that has been deleted (it may still be in the Recycle Bin).

Fix:
1. Confirm the record is deleted: query it with ALL ROWS in Apex, or check the Recycle Bin.
2. Restore it with undelete if it should exist, or remove the stale reference.
3. Refresh cached IDs in integrations that hold on to old records.

```apex
List<Account> a = [SELECT Id FROM Account WHERE Id = :id ALL ROWS];
undelete a;
```

### DELETE_FAILED

Typical message: `DELETE_FAILED, Your attempt to delete <record> could not be completed because it is associated with ...`

Cause: The record is in use by another record or setting, such as a related record that restricts deletion, so it cannot be deleted.

Fix:
1. Read the end of the message: it names what the record is associated with.
2. Remove or reassign the associated records or references first, then delete again.
3. Check lookup fields whose delete behavior is set to Don't allow deletion.

### MALFORMED_ID

Typical message: `MALFORMED_ID, malformed id 001XXXXXXXX`

Cause: A value passed as an ID is not a valid 15 or 18 character Salesforce ID (wrong length, stray characters, or changed case in an 18-character ID).

Fix:
1. Check for whitespace, quotes or truncated values in the ID.
2. Convert and validate the ID with the ID converter.
3. In SOQL filters, compare an ID field with a valid ID, not a name or a label.

See also: [Salesforce ID converter](https://sfdxtalk.com/tools/salesforce-id-converter/)

### INVALID_TYPE_ON_FIELD_IN_RECORD

Typical message: `INVALID_TYPE_ON_FIELD_IN_RECORD, Close Date: value not of required type: ...`

Cause: A value does not match the data type of its field, for example text in a number field or a date in the wrong format.

Fix:
1. Check the field named in the message and its data type.
2. Format dates as YYYY-MM-DD and datetimes in ISO 8601 for API and data loads.
3. Remove thousands separators and currency symbols from number values.

### ENTITY_IS_LOCKED

Typical message: `ENTITY_IS_LOCKED, entity is locked`

Cause: The record is locked because an approval process is pending on it, so it cannot be edited until the approval finishes.

Fix:
1. Open the record and check for a pending approval request.
2. Ask the approver to approve or reject it, or have an admin recall or unlock it.
3. In automation, check Approval.isLocked or the lock status before updating.

### UNABLE_TO_LOCK_ROW

Typical message: `UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record`

Cause: Two transactions tried to update the same or related records at once, so one timed out waiting for the lock, or they deadlocked. Roll-up summary fields and child records of the same parent are common causes because the parent is locked.

Fix:
1. Retry the failed operation; the error is often transient.
2. In bulk loads, lower the batch size or switch to serial processing, and sort records by parent so batches do not compete for the same parent.
3. Avoid running many jobs against the same parent record at the same time.
4. In Apex, SOQL FOR UPDATE locks records on purpose; keep the transaction short.

## Access and login

### INSUFFICIENT_ACCESS_OR_READONLY

Typical message: `INSUFFICIENT_ACCESS_OR_READONLY, insufficient access rights on object id`

Cause: The running user lacks the permission or record access needed for the action, for example edit or delete rights on that record through ownership, sharing or object permissions.

Fix:
1. Check object permissions (create, read, edit, delete) for the user in their profile and permission sets.
2. Check record access: the owner, role hierarchy, sharing rules and org-wide defaults for the object.
3. Reproduce as the user: use Login As in a sandbox or run the Apex in a System.runAs test.

### INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY

Typical message: `INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id`

Cause: The save affects another record that this one references (for example a lookup target or a parent), and the user cannot access that referenced record.

Fix:
1. Identify the referenced record from the ID in the message or from the lookup fields you are setting.
2. Give the user access to it through sharing, or use a user who has access.
3. In Apex that must act on records the user cannot see, run it in a class declared with sharing settings that fit the design, and document the reason.

### INVALID_SESSION_ID

Typical message: `INVALID_SESSION_ID: Session expired or invalid`

Cause: The session ID or access token sent with the request is expired, malformed or no longer valid, or it was sent to the wrong instance URL.

Fix:
1. Log in or refresh the OAuth access token and retry.
2. Use the instance_url returned at login as the base URL for API calls.
3. Check that the Authorization header is "Bearer <token>" with no extra characters.

### INVALID_LOGIN

Typical message: `INVALID_LOGIN: Invalid username, password, security token; or user locked out.`

Cause: The login credentials are not valid, the user is locked out, or the maximum number of logins has been exceeded.

Fix:
1. Verify the username and password, and that the user is active and not locked out.
2. If logging in from an IP outside the trusted range, append the security token to the password or add the IP to a trusted range.
3. Confirm you are using the right login URL (login.salesforce.com, test.salesforce.com or the My Domain URL).

### INVALID_FIELD_FOR_INSERT_UPDATE

Typical message: `INVALID_FIELD_FOR_INSERT_UPDATE, Unable to create/update fields: <Field>. Please check the security settings of this field...`

Cause: A field in the request cannot be written: it is read-only for the user through field-level security, or it is a formula, auto-number or system field.

Fix:
1. Check field-level security for the field in the user's profile and permission sets.
2. Check the field type: formula, roll-up summary and auto-number fields cannot be set.
3. Remove the field from the request or load file if it should not be written.

## SOQL and queries

### INVALID_FIELD

Typical message: `INVALID_FIELD: No such column 'Foo__c' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name.`

Cause: The query names a field that does not exist on the object, is misspelled, lacks the __c suffix, or is not visible to the running user.

Fix:
1. Check the field API name on the object in Object Manager (labels differ from API names).
2. Custom fields end with __c, and relationship paths use __r.
3. Check that the user has field-level security access to the field.
4. If the field is in a package, include the namespace prefix.

```soql
SELECT Id, Region__c FROM Account // field must be Region__c, not Region
```

### MALFORMED_QUERY

Typical message: `MALFORMED_QUERY: unexpected token: 'FROM'`

Cause: The query string has invalid SOQL syntax, or exceeds a query limit such as the maximum query length.

Fix:
1. Look at the token named in the message and the text right before it.
2. Check commas between fields, quotes around strings and the order SELECT, FROM, WHERE, GROUP BY, ORDER BY, LIMIT.
3. Test the query in the Developer Console Query Editor.

### INVALID_TYPE

Typical message: `INVALID_TYPE: sObject type 'Foo' is not supported.`

Cause: The object name in the query or API call does not exist, is misspelled, lacks __c, or the user cannot see the object.

Fix:
1. Check the object API name in Object Manager.
2. Custom objects end with __c.
3. Check that the user has Read access to the object.

### QUERY_TIMEOUT

Typical message: `QUERY_TIMEOUT: Your query request was running for too long.`

Cause: The query took too long, usually because it filters on non-indexed fields over a large object or returns too much data.

Fix:
1. Filter on indexed fields (such as Id, Name, lookups, external IDs) and use a narrower date range.
2. Remove leading wildcards and negative filters like != where you can.
3. For large exports, use Bulk API or query in smaller slices.

### System.QueryException: Non-selective query against large object type

Typical message: `System.QueryException: Non-selective query against large object type (more than 200000 rows). Consider an indexed filter or contact salesforce.com about custom indexing.`

Cause: A query in a trigger filters on fields that are not selective on an object with a large number of records, so Salesforce refuses to run it.

Fix:
1. Add a filter on an indexed field that narrows the results to a small share of records.
2. Avoid filtering on formula fields or fields with mostly the same value.
3. Ask Salesforce Support about a custom index when the filter is correct but still not selective.

### System.QueryException: Aggregate query has too many rows for direct assignment

Typical message: `System.QueryException: Aggregate query has too many rows for direct assignment, use FOR loop`

Cause: A query that returns more rows than direct assignment to a list or variable allows was assigned directly.

Fix:
1. Use a SOQL for loop to process the rows in chunks.
2. Add filters or LIMIT to return fewer rows.

```apex
for (Account a : [SELECT Id FROM Account]) {
    // process one record at a time
}
```

See also: [Governor limits reference](https://sfdxtalk.com/tools/governor-limits/)

### System.QueryException: List has no rows for assignment to SObject

Typical message: `System.QueryException: List has no rows for assignment to SObject`

Cause: Apex assigned the result of a query straight to a single record, but the query returned no rows (or more than one, which gives a different message).

Fix:
1. Assign the query to a List and check isEmpty() or size() before using it.
2. Or add LIMIT 1 and handle the empty case.
3. In tests, create the data the query expects.

```apex
List<Account> rows = [SELECT Id FROM Account WHERE Name = :n LIMIT 1];
if (!rows.isEmpty()) {
    Account a = rows[0];
}
```

### System.SObjectException

Typical message: `System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Industry`

Cause: Apex read a field on a record that was queried without that field in its SELECT list.

Fix:
1. Add the named field to the SELECT list of the query that loaded the record.
2. If the record was passed in from elsewhere, query it again with the fields you need.

## Apex runtime

### System.NullPointerException

Typical message: `System.NullPointerException: Attempt to de-reference a null object`

Cause: Code called a method or read a field on a variable that is null, such as an unqueried relationship, an empty map lookup or an uninitialised variable.

Fix:
1. Use the line and column in the stack trace to find the expression that is null.
2. Add null checks, or use the safe navigation operator ?. in Apex.
3. Initialise collections, and check map.get(key) results before using them.

```apex
String name = acc?.Owner?.Name; // returns null instead of throwing
```

### System.ListException

Typical message: `System.ListException: List index out of bounds: 0`

Cause: Code read an index that is not in the list, most often element 0 of an empty list.

Fix:
1. Check list.isEmpty() or size() before reading an element.
2. Check the loop bounds when iterating by index.

### System.DmlException

Typical message: `System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Name]: [Name]`

Cause: A DML statement failed. This is a wrapper: the real reason is the status code after "first error:".

Fix:
1. Find the status code after "first error:" and look it up in this list.
2. The row number is zero-based: row 0 is the first record in the list.
3. Use Database.insert(records, false) and inspect each SaveResult to see every failure instead of only the first.

```apex
Database.SaveResult[] res = Database.insert(records, false);
for (Database.SaveResult r : res) {
    if (!r.isSuccess()) System.debug(r.getErrors()[0].getStatusCode() + ': ' + r.getErrors()[0].getMessage());
}
```

### System.CalloutException: You have uncommitted work pending

Typical message: `System.CalloutException: You have uncommitted work pending. Please commit or rollback before calling out`

Cause: Apex made a callout after DML in the same transaction. A callout is not allowed while there are uncommitted changes.

Fix:
1. Make the callout before the DML.
2. Or move the callout (or the DML) to a Queueable or @future method so it runs in its own transaction.

### System.TypeException

Typical message: `System.TypeException: Invalid conversion from runtime type Account to Contact`

Cause: A cast or conversion is not valid for the actual runtime type of the value, or a string could not be converted to a number, date or ID.

Fix:
1. Check the real type with instanceof before casting.
2. Validate strings before converting them to numbers or dates.

### MIXED_DML_OPERATION

Typical message: `MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa)`

Cause: One transaction changed both a setup object (such as User, Group or PermissionSetAssignment) and a non-setup object (such as Account). Salesforce limits this mix.

Fix:
1. Move one of the DML operations to a separate transaction, such as a Queueable or @future method.
2. In tests, wrap the setup-object DML in System.runAs(user) { ... }.

### SELF_REFERENCE_FROM_TRIGGER

Typical message: `SELF_REFERENCE_FROM_TRIGGER, Object (id = 001...) is currently in trigger X, therefore it cannot recursively update itself`

Cause: A trigger updated or deleted the same record it is running for, in a way that is not allowed, such as updating the record from its own before trigger by DML.

Fix:
1. In a before trigger, set field values on Trigger.new directly instead of using DML.
2. Do not delete the triggering record from its own trigger.
3. Use a static flag to guard against recursion if two triggers update each other.

### CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

Typical message: `CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, MyTrigger: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object`

Cause: An error occurred in a trigger, flow or process that ran while saving. This is a wrapper: the real error is the exception named after "caused by". The status code can also mean a missing permission to create, update or activate the record.

Fix:
1. Read the text after "caused by:" and find that exception in this list.
2. The trigger name and line number in the message show where it failed.
3. Reproduce with the same data and open the debug log to see the execution path.

### Variable does not exist

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).

Fix:
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.

## Integration and API

### REQUEST_LIMIT_EXCEEDED

Typical message: `REQUEST_LIMIT_EXCEEDED: TotalRequests Limit exceeded.`

Cause: The org exceeded either the concurrent request limit or the request limit for its API usage, so Salesforce rejects new API requests.

Fix:
1. Check API usage in Setup under System Overview and the Limits resource of the REST API.
2. Batch work: use composite requests, Bulk API or sObject Collections to use fewer calls.
3. Cache reads and avoid polling in tight loops; stop runaway integrations.

See also: [Governor limits reference](https://sfdxtalk.com/tools/governor-limits/)

### System.CalloutException: Unauthorized endpoint

Typical message: `System.CalloutException: Unauthorized endpoint, please check Setup->Security->Remote site settings.`

Cause: Apex called an external URL that is not allowed: the URL is not registered as a Remote Site Setting, or it is not covered by a Named Credential.

Fix:
1. Prefer a Named Credential for the callout and use the callout: URL syntax.
2. Or add the exact base URL as a Remote Site Setting in Setup.
3. Check the protocol and host; http and https are different.

### invalid_grant

Typical message: `{"error":"invalid_grant","error_description":"authentication failure"}`

Cause: An OAuth token request was refused. Common reasons: wrong username, password or token, a user the connected app does not allow, an expired or revoked refresh token, or a login URL that does not match the org (production versus sandbox or My Domain).

Fix:
1. Check the token endpoint host matches the org type (login.salesforce.com, test.salesforce.com or your My Domain).
2. Check the connected app policies: permitted users and pre-authorized profiles or permission sets.
3. For JWT bearer flow, check the username, the certificate and that the app is pre-authorized for that user.
4. Request a new refresh token if the old one was revoked.

## Governor limits

### System.LimitException: Too many SOQL queries

Typical message: `System.LimitException: Too many SOQL queries: 101`

Cause: A transaction ran more SOQL queries than the per-transaction governor limit, usually a query inside a loop.

Fix:
1. Move queries out of loops: collect IDs first, then query once with IN :ids.
2. Store results in a Map to look them up inside the loop.
3. Check the debug log for the CUMULATIVE_LIMIT_USAGE section to see which code ran the queries.

See also: [Governor limits reference](https://sfdxtalk.com/tools/governor-limits/)

### System.LimitException: Too many DML statements

Typical message: `System.LimitException: Too many DML statements: 151`

Cause: A transaction ran more DML statements than the governor limit, usually a DML call inside a loop.

Fix:
1. Add records to a list inside the loop and run one DML statement afterwards.
2. Check that triggers, flows and process automation on the same object are not each doing their own updates.

See also: [Governor limits reference](https://sfdxtalk.com/tools/governor-limits/)

### System.LimitException: Too many query rows

Typical message: `System.LimitException: Too many query rows: 50001`

Cause: The queries in one transaction returned more rows in total than the governor limit allows.

Fix:
1. Filter queries to return only the rows you need and add LIMIT.
2. Process big sets in Batch Apex, which gets fresh limits per batch.

See also: [Governor limits reference](https://sfdxtalk.com/tools/governor-limits/)

### System.LimitException: Apex CPU time limit exceeded

Typical message: `System.LimitException: Apex CPU time limit exceeded`

Cause: Apex code, triggers, flows and other automation in the transaction used more CPU time than allowed. Nested loops, heavy string work and many automations on one record are common causes.

Fix:
1. Use the debug log with limits and profiling to find the slow code.
2. Replace nested loops over lists with Maps.
3. Move long work to Queueable or Batch Apex.
4. Check for many triggers, flows and process automation firing on the same object.

See also: [Governor limits reference](https://sfdxtalk.com/tools/governor-limits/)

## Deployment

### Code coverage failure: Average test coverage across all Apex Classes and Triggers is below the required percent

Typical message: `Code coverage failure: Average test coverage across all Apex Classes and Triggers is 62%, at least 75% required`

Cause: A deployment to production that runs tests did not reach the required org-wide Apex test coverage of 75 percent.

Fix:
1. Write tests for the classes with the lowest coverage; assert behavior, not only coverage.
2. Run all local tests in a sandbox and check coverage per class before deploying.
3. Check that failing tests are not lowering coverage.

### Test coverage of selected Apex Trigger is 0%

Typical message: `Test coverage of selected Apex Trigger is 0%, at least 1% test coverage is required`

Cause: A trigger in the deployment has no test coverage. Triggers need some coverage to deploy to production.

Fix:
1. Write a test that inserts, updates or deletes records so the trigger runs.
2. Include that test class in the deployment and run it.
3. Make sure the test creates its own data and performs the DML the trigger listens for (insert, update or delete).

```apex
@isTest
private class AccountTriggerTest {
    @isTest static void insertsFireTrigger() {
        insert new Account(Name = 'Test');
    }
}
```

### no CustomObject named X found

Typical message: `In field: object - no CustomObject named Invoice__c found`

Cause: A component in the deployment (a layout, permission set, profile, flow or field) refers to an object that is neither in the target org nor part of this deployment. The same message pattern applies to other types, such as "no CustomField named ...".

Fix:
1. Add the missing object or field to the package.xml or deploy source so it ships in the same deployment.
2. Check the object API name spelling and the namespace prefix.
3. If the component should not reference it, remove the reference from the metadata file.

### Dependent class is invalid and needs recompilation

Typical message: `Dependent class is invalid and needs recompilation: Class MyClass : Variable does not exist: Region__c`

Cause: An Apex class that the deployed code depends on no longer compiles, often because a field or class it uses was changed, removed or is missing in the target org.

Fix:
1. Read the text after the second colon: it is the actual compile error in the dependent class.
2. Deploy the missing or changed fields and classes together with the code.
3. Recompile all classes in Setup after fixing the cause.
