I've seen Apex code examples write out Schema.SObjectField
-typed constants in both of these formats:
Schema.Account.AccountNumber
Schema.Account.SObjectType.Fields.AccountNumber
Why two different approaches?
Are there any features I'd lose by choosing the concise one instead of the long one?
I can see how the latter would be useful if stopped at the 4th piece, Fields
, and were then iterating over its contents. But I've seen examples where it's literally written out as a 5-part literal, and I'm not sure exactly why.
Note: Not quite the same question at Account.sObjectType.getDescribe() vs Schema.sObjectType.Account in my opinion.
- The other two "feel" noticeably different from each other due to arriving at the same
Schema.DescribeSObjectResult
via very different "first class listed" paths, whereas I'm interested in two that "feel" noticeably redundant, yet both appear in the wild (e.g. fflib tutorials).- Also, while I'm glad to be pointed to that thread and see that there's an answer of "nope, no noticeable difference" for that particular scenario that deals with
Schema.DescribeSObjectResult
s, this is aboutSchema.SObjectField
(and, again, a different set of syntaxes from that question).Just to be safe, I'd rather leave this question open until someone chimes in with an opinion about this particular case and whether people with the "5-part literal" approach are just being needlessly verbose, or whether there's a reason to use the "5-part literal" over the "3-part literal."
Thanks so much!
Schema.DescribeSObjectResult
. I'm asking about the reasons to choose between two different approaches to returning aSchema.SObjectField
-- and whose syntax don't even start with different outermost classes, at that. Thanks for bringing the other post to my attention, though!Schema.
away, e.g.Product2.language__c.getDescribe(FieldDescribeOptions.FULL_DESCRIBE)
works fine