function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
creemejcreemej 

Why does this sample code violates the ChildRelationship Governor Limit = 10

Hi,

I try to understand this Governor Limit (from apex_language_reference/winter'09):

You can only use 10 getChildRelationships method calls per sObject during the execution of an Apex script.
For example, an Apex script can execute 10 getChildRelationships method calls for Account, then another 10 for Lead. For more
information about governor limits, see Understanding Execution Governors and Limits on page 142.

I read: 10 for Account, 10 for Contact, 10 for Contract  ... but not 10 for ALL !!!

Is there a way to do something dynamicaly?

Thanks,
creemej

Schema.DescribeSObjectResult r;
List<Schema.ChildRelationship> childRelationships;

//Account
r = Account.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Account.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Account.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Account.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();

//Contact
r = Contact.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Contact.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Contact.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Contact.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Contact.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();

//Contract
r = Contract.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Contract.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Contract.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Contract.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Contract.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();

creemejcreemej
This gives the same exception.
Is this normal or is this a bug?

Schema.DescribeSObjectResult r;
List<Schema.ChildRelationship> childRelationships;

r = Account.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Contact.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Contract.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Lead.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Case.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Solution.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = User.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Idea.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Asset.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Opportunity.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();
r = Partner.SObjectType.getDescribe();
childRelationships = r.getChildRelationships();