+ 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

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.