Loading
Scalability
ApexGuru Antipattern: SOQL with Negative Expressions

ApexGuru Antipattern: SOQL with Negative Expressions

SOQL queries that use negative expressions such as NOT IN or != don't index effectively, leading to full-table scans. Less-efficient database operations increase query time and CPU usage. Avoid negative expressions. Use positive expressions wherever possible.

Scope

Detection only

Detection Example

apex
  [SELECT Id FROM Opportunity WHERE StageName NOT IN ('Closed Won', 'Closed Lost')];
 
正在載入
Salesforce Help | Article