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
Archana BattaArchana Batta 

Can we query for Schema inside a for loop

Hello Everyone,

Is it Ok to have Schema statements inside for loop? Will it affect governor limits?

For ex, i want to have some statement like this
for(Employee emp : empList){
   String str = Schema.SObjectType.Employee__c.getRecordTypeInfosById().get(Employee__c.RecordTypeId).getName();
}

Thanks & Regards,
B Archana
Arunkumar RArunkumar R
Hi,

No governor limit for schema describe call from Summer'14 release onwards. But it is not a good practice and it will impact performance. Try to get all your schema related details before for loop and store it in MAP and use it.

Reference:
https://releasenotes.docs.salesforce.com/en-us/summer14/release-notes/rn_apex_describe_limit_removal.htm