I need to count the total number of custom objects available in a Salesforce organization. Is there a way to accomplish this?
1 Answer
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 );
-
-
@ookkk yes sure. Declare a public integer variable and then display it in VF page. Nov 25, 2016 at 9:07
-
1thanks tushar..i need custom objects only and I can see custom settings also.– ookkkNov 28, 2016 at 5:44