---
schema_version: "1"
id: d4d191f3921d086a1a478f163113ebe556b3ab58ac5c75efb91c95a541742772
title: AvoidMultipleMassSchemaLookups Rule (Retired)
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/code-analyzer/salesforce-code-analyzer/guides/v3x/salesforce-graph-engine/avoidmultiplemassschemalookup-rule.md
canonical_url: https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/guide/avoidmultiplemassschemalookup-rule.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: c9fb94a0285fcb7b6539793f085594a6d0da3d77e550f28cfd3239c3b52e8b66
products:
  - Salesforce Code Analyzer
---
# AvoidMultipleMassSchemaLookups Rule (Retired)

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

## Definition

- Source

  - : `@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.

- Sink

  - : `Schema.getGlobalDescribe()`.
    `Schema.describeSObjects(...)`.

## Interpreting Results

Match any violation message that you receive with these cases to understand more about the violation.

### Loop Case

> `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 Schema Lookups Are Invoked Case

> 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.

### More Than One Execution in a Path Case

> `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
