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
, andWhileLoopStatement
- 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 loopSchema.describeSObjects(...)
within a loopSchema.getGlobalDescribe()
preceding aSchema.getGlobalDescribe()
orSchema.describeSObjects(...)
method call anywhere in the pathSchema.describeSObjects(...)
preceding aSchema.describeSObjects(...)
orSchema.getGlobalDescribe()
method call anywhere in the path
- Source
@AuraEnabled
-annotated methods.@InvocableMethod
-annotated methods.@NamespaceAccessible
-annotated methods.@RemoteAction
-annotated methods. Any method returning aPageReference
object.public
-scoped methods on Visualforce Controllers.global
-scoped methods on any class.Messaging.InboundEmailResult handleInboundEmail()
methods on implementations ofMessaging.InboundEmailHandler
. Any method targeted during invocation.- Sink
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