Fetch all standard Salesforce objects in apex

You are currently viewing Fetch all standard Salesforce objects in apex
Fetch all standard salesforce objects in apex

In one of our article we have discussed how to fetch all custom objects in apex . Today we will learn  how to get all Custom and Standard Objects .

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 ,  to find all required fields on Object and so on .

Get all Standard and Custom Objects

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

The given approach will return all Objects available on Salesforce org . Where some objects are

not isAccessible ,

not isCreateable

and not isQueryable .

Filtering Objects in APEX

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

The about code will give objects which are isAccessible and isQueryable and isCreateable .Check how to find all the Custom Objects in Salesforce.

Hope you learn something new Today .

Thank you.

Leave a Reply