In Salesforce, query performance depends heavily on whether the query can use indexed fields. The platform automatically creates indexes on certain
system fields to speed up data retrieval.
LastModifiedDate is not indexed by default, which means queries filtering on this field require full table scans. When your
organization has large amounts of data (over 100,000 records), these non-selective queries can become extremely slow or even fail due to governor
limits.
SystemModStamp, on the other hand, is automatically indexed by Salesforce. Both fields track when records were last modified, but
SystemModStamp provides the same filtering capability with much better performance.
The difference becomes critical in production environments with large datasets, where non-selective queries can cause timeouts, poor user
experience, and may trigger Salesforce’s non-selective query prevention mechanisms.
What is the potential impact?
Using LastModifiedDate in SOQL queries can lead to:
- Slow query execution times, especially with large datasets
- Potential query timeouts and failures
- Poor application performance and user experience
- Risk of hitting Salesforce governor limits
- Non-selective query errors when querying objects with more than 100,000 records