4

I need to count the total number of custom objects available in a Salesforce organization. Is there a way to accomplish this?

0

1 Answer 1

8

You can easily do this using Global Describe

map<String, Schema.SObjectType> GlobalMap = Schema.getGlobalDescribe(); 
for (Schema.SObjectType Obj : GlobalMap.values()) {
    Schema.DescribeSObjectResult ObjDesc = Obj.getDescribe();
    system.debug('Object Name: ' + ObjDesc.getName());
}
System.debug(GlobalMap.size() );

Or if you want to see only custom objects then

Integer count = 0;
map<String, Schema.SObjectType> GlobalMap = Schema.getGlobalDescribe(); 
    for (Schema.SObjectType Obj : GlobalMap.values()) {
        Schema.DescribeSObjectResult ObjDesc = Obj.getDescribe();
        if(ObjDesc.iscustom()){
           count ++;
           system.debug('Object Name: ' + ObjDesc.getName());
        }
    }
System.debug('Custom Object '+ count );
3
  • can we display count value in visual force page also?
    – ookkk
    Nov 25, 2016 at 8:58
  • @ookkk yes sure. Declare a public integer variable and then display it in VF page. Nov 25, 2016 at 9:07
  • 1
    thanks tushar..i need custom objects only and I can see custom settings also.
    – ookkk
    Nov 28, 2016 at 5:44

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.