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

Metadata API exception: IO Exception: Exceeded max size limit of 3000000

Hi All,

I am using Metadata API to get information about org. I want to retrieve all custom fields present in my org. I am using listMetadata() method which returns list of components. Below is my code:

MetadataService.MetadataPort service = createService();            
        List<MetadataService.ListMetadataQuery> queries = new List<MetadataService.ListMetadataQuery>();       
        MetadataService.ListMetadataQuery queryLayout = new MetadataService.ListMetadataQuery();
        //queryLayout.folder = MetaDataFolder;
        queryLayout.type_x ='CustomField';
        MetadataService.FileProperties[] fileProperties; 
         fileProperties= service.listMetadata(queries, 29); //here 29 is api version
        }catch(exception e){
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,e.getMessage()));

I am get exception as "IO Exception: Exceeded max size limit of 3000000". I know that number of custom fields present in my org is to much and the response that I am getting exceeding the allowed limit of 3MB. I want to list all custom fields present in my org. Same exception is coming when I am retrieving few other metadata(like all profile). Above mentioned code works fine in my developer org but in sandbox, its not working as number of metadata components is too much in my sandbox. 

I tried retrieving the components using Workbench which also uses metadata api. Workbench retrieved all components successfully. So there will be some mechanism in metadata API through which I can retrieve large number of components. I saw few post where people says to retrieve info in different chunks by spliting single request in 2 or 3 different request. But in my case, I am not able to split my request as I want all custom fields.

Can anyone help me on this .

Thanks in advance.

Sunil kumar

I am also facing similar issue, were you able resolve this ?
I am also facing the same issue. Any solution?
Hi All,

Has anyone faced similar issue?? Any solution for this?

Hi All,

We have resolved this by using combination of metadata Api and tooling api. By using metadata Api, we are fetching all object available and then fetching all custom fields by using tooling api by using below query:

select id,developername from CustomField where TableEnumOrId=:objectid

for standard objects objectid will be their Api name and for custom object you will get id for custom objects which you can get by using metadat api(by doing listmetadata() call..

We have created 2 picklist. user first select custom field from first picklist, then system will do metadata call to listmetadata() method and will give all objects along with their id. We displayed all retrieved object in 2nd picklist. When user select object and click on search, we do call for custom field using tooling api by sending above query and will get response in json and will parse that to show it to user.

Retriving all custom field at one time will be very difficult as callout response can not return these large number of fields at once. You can use tooling api either to return all fields at once by below query :

select id,developername from CustomField

As it return json, it might possible you will get all custom fields at once. Just check it out. if here also you are getting exception, then you have to send request based on object by sending query with object filter.

Hope this will help you.
[If it solves your problem, please mark it as solution]