getName() used to get API NAME of Salesforce object. By using getLabel() method we can find label of any Salesforce object.
See in action - How to identify Standard & Custom Salesforce Objects
How the code works
The first snippet loops through all objects and prints whether each one is custom, using isCustom() from the object describe. The second snippet does the same check for one object, cbugs__Student__c, which is a custom object in a namespace.
Problem: getGlobalDescribe inside the loop
Both snippets call Schema.getGlobalDescribe() again for every object. That method is expensive, and calling it hundreds of times can cause a CPU time limit error. The loop already holds each object token, so the second call is not needed.
Simpler and faster
// Check one object
Boolean isCustom = Schema.getGlobalDescribe().get('cbugs__Student__c').getDescribe().isCustom();
System.debug('Is custom: ' + isCustom);
// Check all objects
for (Schema.SObjectType objTyp : Schema.getGlobalDescribe().values()) {
Schema.DescribeSObjectResult d = objTyp.getDescribe();
System.debug(d.getLabel() + ' | custom = ' + d.isCustom());
}
If you only need one object, use the first part and skip the loop completely.
FAQ
Is an object ending in __mdt custom? isCustom() returns true for custom metadata types, platform events and other custom object types, not only for __c.
What if the object name is wrong? The get call returns null and the next call fails with a null pointer error, so check for null first.