Inspector false positive when referencing fields named 'SobjectType'
SFDC has a few SObjects (QueueSObject, RecordType, …) where there is a field on the object called “SObjectType”. The inspector gets confused, thinking I’ve coded a reference to an object of type SobjectType when in fact, I’m referring to a field named SobjectType on an SObject.
SObjectField fld = QueueSobject.SobjectType;
SobjectField[] flds = new List<SObjectField> {QueueSobject.SObjectType};
Compiles and runs fine.
Comments (4)
-
repo owner -
repo owner I spoke with some key folks at Salesforce about this. It's a known bizarre behavior. I'm not 100% sure what I'm going to do about it in IC2 given how non-standard it is. I'm hesitant to implement too many workarounds, so I may just suppress the illegal assignment code inspector in that specific instance. It won't fix things like chained code completions and such, but it would at least quiet down the noise.
-
repo owner Change committed to ignore type mismatch for
SobjectType
fields when assigned toSObjectField
if they aren't of typeSObjectType
. This is actually just an extension of an existing inspection exception rule that was previously not applied to theSObjectType
field but now is selectively. This will be included in the next build. -
repo owner - changed status to resolved
Delivered in 2.1.4.8.
- Log in to comment
There's something very weird going on here with the
SobjectType
fields on some of these standard SObjects. It actually seems that there's a class variable namedSObjectType
that's of typeSchema.SObjectField
and there's also an instance variable namedSobjectType
that's of typeString
. For example, the following compiles just fine:I'm not going to deliver any changes here until I figure out what's going on. It seems to me that there's something happening that's otherwise unsupported in the Apex language.