You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
Methods Schema.getGlobalDescribe() or Schema.describeSObjects should be called once per an apex transaction and should never be called inside a loop.
Code Sample: This should include code, that should be flagged by the rule. If possible, the "correct" code
according to this new rule should also be demonstrated.
//to avoidSet<String> fieldNameSet = newSet<String> {'Id'};
for (StringfieldNameOrDefaultValue : fieldNameOrDefaultValueList) {
if (Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap().containsKey(fieldNameOrDefaultValue.trim() )) {
fieldNameSet.add(fieldNameOrDefaultValue);
}
}
//correctSet<String> fieldNameSet = newSet<String> {'Id'};
Map<String, Schema.SObjectField> fieldMap = Schema.getGlobalDescribe().get(objectName).getDescribe().fields.getMap();
for (StringfieldNameOrDefaultValue : fieldNameOrDefaultValueList) {
if (fieldMap.containsKey(fieldNameOrDefaultValue.trim())) {
fieldNameSet.add(fieldNameOrDefaultValue);
}
}
Proposed Rule Name: OperationWithHighCostInLoop
Proposed Category: Performance
Description:
Methods Schema.getGlobalDescribe() or Schema.describeSObjects should be called once per an apex transaction and should never be called inside a loop.
Code Sample: This should include code, that should be flagged by the rule. If possible, the "correct" code
according to this new rule should also be demonstrated.
Additional Information:
See also: Why is Schema.describeSObjects(types) Slower Than Schema.getGlobalDescribe()?
Possible Properties:
The text was updated successfully, but these errors were encountered: