0

I have used the below method of getting RecordTypeIds for any record many times and it has worked for me-

Id RTid = Order.sObjectType.getDescribe().getRecordTypeInfosByName().get('Export Order').getRecordTypeId()

wierdly, it's throwing an error today for a specific class whereas in another class is getting compiled-

Error: Compile Error: Invalid field sobjecttype for SObject Order at line x column y

The same method executes well in Anonymous Apex.

Any ideas what I'm doing wrong.

For the time being I've changed my code to

Id RTid = Schema.SObjectType.Order.RecordTypeInfosByName.get('Export Order').RecordTypeId;;

1 Answer 1

1

The usual cause of this sort of problem is a local variable or class member or class that is also called order (case doesn't matter) taking precedence over the type name.

A way to avoid that is to add the Schema prefix:

Id RTid = Schema.Order.sObjectType.getDescribe()...

(or change the name of the local variable or class member or class).

0

You must log in to answer this question.

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