[SalesForce] System.LimitException: Too many fields describes: 101

For the sake of my programming around this with a makeshift fix:

Is this implying that I am trying to write to more than 100 fields at a time across multiple records..? Or even one record? I can't seem to find a clear definition for this error.

Any help would be appreciated. Thanks.

Best Answer

Look in the code that you have not done any describe call inside the for loop

Schema.DescribeFieldResult F = Account.AccountNumber.getDescribe();

This is an example for field describe .Search for the describe calls in the code and make sure we have out of the for loop.

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_fields_describe.htm

Here is the document of complete list of fielddescribe calls .

There is a limit that in a single context run you can have only 100 fielddescribe calls.This is one of the governor limits of platforms

Here is the class thats causing issue .I see getdescribe inside the for but that may not be issue but please dont call this inside the for loop .Try to bulkify

for(Schema.SObjectField sfield : fieldMap.Values()){
        schema.describefieldresult dfield =   sfield.getDescribe();
        string fname = dfield.getname();      
        //if (fname.indexOf('pb_') > -1 && fname.indexOf(productName) > -1 )
        if (fname == ('pb_Stage_' + productName + '__c')  || fname == ('pb_SubStage_' + productName + '__c') || 
            fname == ('pb_RecordType_' + productName + '__c')  || fname == ('pb_CreateDate_' + productName + '__c') ||
            fname == ('pb_Client_' + productName + '__c')  || fname == ('pb_CloseDate_' + productName + '__c') ||
            fname == ('pb_SubBegin_' + productName + '__c')  || fname == ('pb_SubEnd_' + productName + '__c') ||
            fname == ('pb_Amount_' + productName + '__c')       )
        {
            if (dfield.isUpdateable())
                if (fname == ('pb_Client_' + productName + '__c') )
                    accObj.put(fname, false);
                else
                {
                    accObj.put(fname, null);
                }
        }
    }

    return accObj;

As shown above by Andrew Fawcett you may get in map and this should resolve the issue

Related Topic