You need to sign in to do that
Don't have an account?

return all objects with matching field name
Hello all,
I want all sobject names with matching field name. For ex: I need all the object names which has field My_field__c. I tried following snippet in execute anonymous , but it blowing off saying
Too many fields describes: 101
Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
List<String> objNames = new List<String>();
for(sObjectType s : gd.values()){
if(s.getDescribe().fields.getMap().containsKey('My_field__c')){
objNames.add(s.getDescribe().getName());
}
}
for(String s: objNames){
System.debug('*****' + s);
}
Is there any other way to achieve this ? ...
Yout help is very much appreciated..
You only get 100 describes on the fields property. You can't check all objects, so you'll need a Custom Setting or some other means of limiting your logic. If you need this in Visualforce, you could do it in batches by just processing 100 at a time, and using a callback to check the next set of 100. I'd imagine you'd need a loading screen to take care of this.