System.SObjectException: meaning and how to fix it

SOQL and queries Checked against the official docs on Source: SOAP API Developer Guide: Core Data Types, StatusCode

Quick answer

System.SObjectException: Apex read a field on a record that was queried without that field in its SELECT list. Start with: Add the named field to the SELECT list of the query that loaded the record.

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.

How to fix System.SObjectException

  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.

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 System.SObjectException mean in Salesforce?

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

How do I fix System.SObjectException?

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.

More SOQL and queries 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.