Fetch all Custom Objects in APEX

You are currently viewing Fetch all Custom Objects in APEX
Fetch all Custom Objects in apex

In this article we will give you simplest way to get all custom objects in apex using Schema.getGlobalDescribe().

You know that using Schema.getGlobalDescribe() we can fetch all properties of sObject. We have already used Schema class to fetch all Standard objects , record types from object ,  find all required fields on Object and so on .

Get List of all Custom Objects

We know that every custom object ends with  __c . Here we are going through  all objects present in Salesforce org and if Object contains __c then we are considering  that object as custom object and print that object local name using getLocalName method .

				
					for(Schema.sObjectType info : Schema.getGlobalDescribe().values()) { 
    Schema.DescribeSObjectResult describedInfo = info.getDescribe();
    String objectName = describedInfo.getLocalName();
    if(objectName.contains('__c')) { 
        System.debug('Object Name '+objectName );
    }
}
				
			

The about code will give you all custom objects . Check how to find all the Standard Objects in Salesforce. Also here you can find how to filter Standard objects in APEX.

Hope you learn something new Today .

Thank you…

Leave a Reply