1

Let's say we have a simple code

Schema.DescribeSObjectResult res = Schema.SObjectType.Account;
system.debug(Schema.SObjectType.Account.fields.Name.isAccessible());
system.debug(res.fields.Name.isAccessible());
system.debug(res.isAccessible());

but it fails in line 3 with the message Line: 3, Column: 25 Variable does not exist: Name what did i miss?

1
  • Looks like it works only on Line 2 manner In the example above, the system uses special parsing to validate that the final member variable (Name) is valid for the specified sObject at compile time. When the parser finds the fields member variable, it looks backwards to find the name of the sObject (Account). It validates that the field name following the fields member variable is legitimate. The fields member variable only works when used in this manner.
    – pincet
    Commented Jul 22, 2021 at 13:13

1 Answer 1

4

fields has a Map return type, because your fields is SObjectTypeFields when you use Schema.DescribeSObjectResult.

Schema.DescribeSObjectResult res = Schema.SObjectType.Account;
System.debug(Schema.SObjectType.Account.fields.Name.isAccessible());
System.debug(res.fields.getMap().get('Name').getDescribe().isAccessible());
System.debug(res.isAccessible());

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .