1

I am writing an Apex Rest web service and I do not want to hit the cap of 6 MB on request or response payload or the 12 MB limit for asynchronous APEX.

But the size of the request and responses are not logged in the Debug Logs. Do I have to adjust the Debug Level to get it logged? If not, how can I view them?

Edit: Here is my Apex Rest Web Service Method signature. Can I or can I not hit Salesforce 6 MB limits with this?

    @HttpPatch
    global static String updateBusinessPartner(List<BusinessPartnerUpdatedInfo> businessPartnerList) {
        //some processing here
    RestRequest incomingRequest = RestContext.request;
    System.debug('incomingRequest body:' + incomingRequest.requestBody);//prints null 
    //all the data of the request is inside the List object in the method parameter. requestBody is NULL
    }

How do I get the incoming request size?

2 Answers 2

3

You can Use HTTPRequest and HTTPResponse class method getBodyAsBlob(); to get the response body in blob and then you can check the size.

httpRequest.getBodyAsBlob().size();

httpResponse.getBodyAsBlob().size();

Then you can use this size in your code.

6
  • Hello Tushar, thanks your your answer. But this is the server side. So I have RestRequest and RestResponse objects, not HTTPRequest and HTTPResponse objects. My web service method accepts parameters so there is nothing in the RestRequest.requestBody attribute (it is null). So till now did not get a way to find the request size. Apr 5, 2018 at 11:44
  • 1
    @SFDCDev27 why don't you use responseBody.size() its available. Apr 5, 2018 at 11:50
  • My web service returns nothing, only a string, so that's not what I am worried about. I want the track the parameter size. RestRequest.requestBody will not give that as per the docs 'If the Apex method has no parameters, Apex REST copies the HTTP request body into the RestRequest.requestBody property. If the method has parameters, then Apex REST attempts to deserialize the data into those parameters and the data won't be deserialized into the RestRequest.requestBody property.' Apr 5, 2018 at 12:05
  • 1
    If your service doesn't expect any body, then I don't think you can hit the limit with just parameters. As there is a limit of lot less size that can be sent in url [stackoverflow.com/questions/417142/…
    – metasync
    Apr 5, 2018 at 14:54
  • Hi datasert, I have updated my question. Would love to know your insights. Apr 6, 2018 at 7:00
0

I have not yet found a way to catch the request size when the data is passed as a method parameter(as mentioned in question). I have not yet found an answer whether I can at all hit the limits by that way.

To track the request payload I have thus changed the method signature to

    global static String updateBusinessPartner() { //no params

and I am getting the request size as @TusharSharma mentioned above:

    RestRequest incomingRequest = RestContext.request;
    Blob requestBody = incomingRequest.requestBody;
    System.debug('incomingRequest body:' + requestBody);//Blob
    System.debug('incoming request size..' + requestBody.size());

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .