I have a Schema util class like the following one:
public with sharing class ObjectDescribe {
public static Map<String, Schema.SObjectField> getFieldsMap(sObject obj) {
DescribeSObjectResult describeObject = obj.getSObjectType().getDescribe();
return describeObject.fields.getMap();;
}
}
then to call the getFieldsMap()
method in a class:
public with sharing class TestDescribe {
public static void execute() {
Opportunity obj = new Opportunity();
objectFields = ObjectDescribe.getFieldsMap(obj);
for (String nm : objectFields.keyset()) {
DescribeFieldResult fr = objectFields.get(nm).getDescribe();
}
}
}
The result dependents on the class version:
- Works well: ObjectDescribe class is v48.0, TestDescribe class is v48.0
- Got
System.SObjectException
: ObjectDescribe class is v48.0, TestDescribe class is v35.0
Why does call the Schema.SObjectField.getDescribe()
from a low version class that causes the System.SObjectException
?