AvoidMultipleMassSchemaLookups Rule (Generally Available)

AvoidMultipleMassSchemaLookups is a path-based rule that detects scenarios where expensive schema lookups are made more than one time in a path and cause performance degradation.

AvoidMultipleMassSchemaLookups identifies these methods:

  • Schema.getGlobalDescribe()
  • Schema.describeSObjects(...)

Flagged lookups include:

  • Lookups within these types of loops: ForLoopStatement, ForEachLoopStatement, DoWhileStatement, and WhileLoopStatement
  • Multiple expensive schema lookups that are invoked
  • An expensive schema lookup that is executed multiple times

These common scenarios trigger a violation from AvoidMultipleMassSchemaLookups.

  • Schema.getGlobalDescribe() within a loop
  • Schema.describeSObjects(...) within a loop
  • Schema.getGlobalDescribe() preceding a Schema.getGlobalDescribe() or Schema.describeSObjects(...) method call anywhere in the path
  • Schema.describeSObjects(...) preceding a Schema.describeSObjects(...) or Schema.getGlobalDescribe() method call anywhere in the path

@AuraEnabled-annotated methods. @InvocableMethod-annotated methods. @NamespaceAccessible-annotated methods. @RemoteAction-annotated methods. Any method returning a PageReference object. public-scoped methods on Visualforce Controllers. global-scoped methods on any class. Messaging.InboundEmailResult handleInboundEmail() methods on implementations of Messaging.InboundEmailHandler. Any method targeted during invocation.


Schema.getGlobalDescribe(). Schema.describeSObjects(...).

Match any violation message that you receive with these cases to understand more about the violation.

Schema.getGlobalDescribe was called inside a loop. [ForEachStatement at AuraEnabledFls:27]

Your code calls Schema.getGlobalDescribe() or Schema.describeSObjects(...) inside a loop statement. To move the Schema.getGlobalDescribe() or Schema.describeSObjects(...) outside the loop, modify and then rescan your code.

Multiple expensive schema lookups are invoked. [Schema.describeSObjects at AuraEnabledFls:27]

Your code invokes Schema.getGlobalDescribe() preceded by Schema.describeSObjects. Modify your code so that only one expensive schema lookup is invoked.

Schema.getGlobalDescribe executed multiple times in the call stack. [getFields at AuraEnabledFls:27, getFields at AuraEnabledFls:28, getFields at AuraEnabledFls:29]

Schema.getGlobalDescribe or Schema.describeSObjects is executed multiple times in a single path. Reduce the execution of the method to one time, then rescan your code