I'm struggiling to understand this line of code:


I've read on the Apex Developer Guide that isDeletable is a method of the DescribeSObjectResult class that returns true if the object is deletable from the current user and false otherwise but I still don't understand the line of code mentioned above.

How the access is done if there is no reference to the DescribeSObjectResult class? I can't figure this out.

Schema is a namespace, sObjectType is a class inside the Schema namespace and Contact is an inner class of the sObjectType class without an isDeletable method, so the method shouldn't be callable because it doesn't exsist in the Contact class and there's no reference to the DescribeSObjectResult class, but the code works. Where am I wrong?

Thank you.


Schema.sObjectType.<sObjectName> is a shortcut for Schema.<sobjectName>.sObjectType.getDescribe(). You can prove this to yourself:

System.assert(sObjectType.Contact == Contact.sObjectType.getDescribe());

Also, You can prove that it is indeed a DescribeSObjectResult:

Object o = sObjectType.Contact;
System.assert(o instanceOf DescribeSObjectResult);

This syntax was added a number of releases ago in order to provide a more concise syntax to get object and field describes when you already know the name of the sObject.

Contact is an inner class of the sObjectType class without an isDeletable method

This is where you went wrong. It does indeed have this method available.

Note that this is different than, for example, Contact.sObjectType, which describes a sObjectType of the Contact object. This is a simple token that can be used to create a new sObject in memory:

Contact contactRecord = Contact.sObjectType.newSObject();

Which is typically used when dynamcially creating sObject objects in memory.

| improve this answer | |
  • Thank you, very useful ! – Stefano Mar 20 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.