function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kavya.ax1320kavya.ax1320 

List out only standard object and Custom object using describe function

Hi,

 

Is there a possibility to list out only Standard and Custom objects from the instance using the Schema.describe function.

 

Thanks in advance.

 

 

Jia HuJia Hu
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
for(Schema.SObjectType f : gd) {
System.debug(' ---' + f.getDescribe().getLabel() );
}
Jia HuJia Hu
Standard object only,

List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
for(Schema.SObjectType f : gd) {
if( !f.getDescribe().getName().endsWith('__c') ) {
System.debug(' ---' + f.getDescribe().getLabel() );
}
}
SFFSFF

This solution is of course correct, but if you wanted something similar in a single code block, with some additional useful information:

 

for (Schema.SObjectType f : Schema.getGlobalDescribe().values())
{
  system.debug((f.getDescribe().isCustom() ? 'cst' : 'std') + ' :: ' + 
    f.getDescribe().getLabel() + ' :: ' + 
    f.getDescribe().getName() + ' :: ' + 
    f.getDescribe().getKeyPrefix());
} 

 Good luck!