System.ListException: 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

System.ListException: Code read an index that is not in the list, most often element 0 of an empty list. Start with: Check list.isEmpty() or size() before reading an element.

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.

How to fix System.ListException

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

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

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

How do I fix System.ListException?

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

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.