5

In the current functionality, we retrieve custom labels from the source organization. The labels are retrieved from salesforce into another Salesforce organization. However, when retrieving the labels we hit the 3 MB Web service governor limit. For the other metadata types, we first get the list of all the objects/components, and we break up those components into smaller chunks so that we can get the entire payload which is less than 3 MB.

However, with custom labels, when we just try to get the list of all the custom labels, we hit the exception. So, we have no way of retrieving the names of the custom labels or the complete definition of the custom labels.

We have tried with the metadata API as well as the tooling API.

What are you thoughts on this? How can we retrieve custom labels or custom fields from another organization without hitting this limit.

The maximum number of custom labels in an organization can be 5000. If we assume that the size of each custom level is 200 bytes, then the total size of all the custom tables is 1 MB. However, we hit still the 3 MB exception limit since the encryption/tokenization takes the rest of the space. What can we do to maximize payload size?

Please advise.

  • Can we achieve this via REST based metadata API calls? – Kevin Bellati Feb 9 '15 at 5:51
  • Do you know what exact labels you need when creating a Web Service call? – GrayB Feb 9 '15 at 7:26
  • @GrayB We neither need to get all the custom labels or labels updated in the last XX days. – Kevin Bellati Feb 9 '15 at 13:54
5

You will need to write your own custom API to return labels in batches/chunks.

It should accept Offset parameter. When offset is not passed it should return first 1000 labels. When its is 1 your API should return labels from 1001 to 2000. In your client ORG keep track of offsets and just keep passing next offset till you reach to end.

This way you should not hit 3 MB Web service governor limit.

Here is working code for your reference. I have used this library. You just need to add logic for returning next chunks as described above.

    @RestResource(urlMapping='/ListLabels/*')
    global with sharing class RESTLabelController {

    @HttpGet   
      global static List<String> getLabels() {     
        List<String> lables = new List<String>();

        MetadataService.MetadataPort service = new MetadataService.MetadataPort();
        service.SessionHeader = new MetadataService.SessionHeader_element();
        service.SessionHeader.sessionId = UserInfo.getSessionId();

        List<MetadataService.ListMetadataQuery> queries = new List<MetadataService.ListMetadataQuery>();        
        MetadataService.ListMetadataQuery queryWorkflow = new MetadataService.ListMetadataQuery();
        queryWorkflow.type_x = 'CustomLabel';
        queries.add(queryWorkflow);     

        MetadataService.FileProperties[] fileProperties = service.listMetadata(queries, 25);

        for(MetadataService.FileProperties fileProperty : fileProperties){
            System.debug(fileProperty.fullName);
            lables.add(String.valueOf(fileProperty.fullName));
            If(lables.size() > 1000)
                 break;

        }
     return lables;
  }
}

In workbench rest explorer enter following URL and you should see the result.

/services/apexrest/ListLabels

  • Are you referring to the SOAP API or REST API? Also, I cannot find the offset parameter. – Kevin Bellati Feb 9 '15 at 13:55
  • I am talking about creating new custom API. SOAP or Rest is your choice. developer.salesforce.com/page/… dhruvsoft.com/blog/… – AtulRajguru9 Feb 9 '15 at 15:11
  • I am not really satisfied with the answer. I am not clear when you "write your custom API". well, we need to pull the data using metadata API. What are the other options? We are calling the metadata api from the apex code. – Kevin Bellati Feb 11 '15 at 7:16
  • @AtulRajguru9 Are you sure the solution is feasible without using a middle ware? OP is asking for solution within Salesforce. Is webservice can handle an another call out (metadat api) which has response greater than 6MB of size? – Ashwani Feb 11 '15 at 8:09
  • @KevinBellati, do you know how to create your own Custom API? if not please go through links provided. Standard API will have its own limitation and it does not provide ability of returning labels in clunks. So what i am suggesting is to write your own API so that you can return data in clunks. – AtulRajguru9 Feb 11 '15 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.