1

For the following 2 lines I am getting getting the error: Method does not exist or incorrect signature: void getDescribe() from the type Schema.DescribeFieldResult

Schema.DescribeFieldResult fieldResult = Schema.SObjectType.Case.fields.Type.getDescribe();

Schema.DescribeFieldResult fieldResult = Schema.SObjectType.Case.fields.Subtype__c.getDescribe();

I do not understand the error. Seems Like Type is a reserved word.

2 Answers 2

3

Schema.sObjectType is a DescribesObjectResult, which is why you need to use fields to get to the fields. If you want to get the field token, use <sobjectType>.<fieldName>.

The two following pieces of code are equivalent with regards to the DescribeFieldResult variable.

sObjectField field = Account.Type;
DescribeFieldResult describe = field.getDescribe();
DescribeFieldResult describe = sObjectType.Account.fields.Type;
2

Well, Type is the name of a class (and not one of the reserved keywords), but that's not the issue here.

Schema.SObjectType.Case.fields.Type and Schema.SObjectType.Case.fields.Subtype__c are already of type Schema.DescribeFieldResult as demonstrated in the example of using fields in the DescribeSObjectResult documentation

Schema.DescribeFieldResult dfr = Schema.SObjectType.Account.fields.Name;

DescribeFieldResult doesn't have a getDescribe() method (which makes sense, since it would just return itself).

The somewhat confusing bit is that while fields.<field api name> results in a DescribeFieldResult
fields.getMap() returns a Map<String, Schema.SObjectField>

So if you would use Schema.SObjectType.Case.fields.getMap().get('Type'), then you would need to follow that up with .getDescribe() to get the DescribeFieldResult.

2
  • It'd probably be nice to get some consistency from Salesforce here (you can get the SObject Field token from the DescribeFieldResult, and vice-versa), but this is probably behavior that a lot of customers depend on. So I wouldn't hold my breath on that being changed.
    – Derek F
    Commented Jun 7 at 14:54
  • 1
    The newer sObjectType describe model was intentional (although confusing). It's not going to change because it's working as designed. To get an sObjectType token, you use <sobjectType>.sObjectType, to get a describe it's sObjectType.<sobjectType>. The docs could do better to call that out, though.
    – sfdcfox
    Commented Jun 7 at 15:14

You must log in to answer this question.

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