I am basically sending a PDF as a binary file but the request is not going anywhere.

The stack trace is following:

23:24:18.100 (138575175)|USER_DEBUG|[28]|DEBUG|50977
23:24:18.100 (138583678)|SYSTEM_METHOD_EXIT|[28]|System.debug(ANY)
23:24:18.100 (138588576)|STATEMENT_EXECUTE|[29]
23:24:18.100 (138602917)|SYSTEM_METHOD_ENTRY|[29]|System.Http.send(ANY)
23:24:18.100 (138714671)|CALLOUT_REQUEST|[29]|System.HttpRequest[Endpoint=callout:Test/api/2.0/files/content, Method=POST]
23:24:18.170 (170220330)|UNKNOWN|NamedCallout[Named Credential Id=0XADO000000Gmr4, Named Credential Name=Test, Status Code=-1, Content-Type=null, Response Size bytes=0, Overall Callout Time ms=16, Connect Time ms=2
23:24:18.100 (170938514)|EXCEPTION_THROWN|[29]|System.CalloutException: Syntax error
23:24:18.100 (171132054)|HEAP_ALLOCATE|[29]|Bytes:16
23:24:18.100 (171173206)|SYSTEM_METHOD_EXIT|[29]|System.Http.send(ANY)
23:24:18.100 (171851342)|VARIABLE_SCOPE_BEGIN|[30]|e|Exception|true|false
23:24:18.100 (171971355)|VARIABLE_ASSIGNMENT|[30]|e|"common.apex.runtime.impl.ExecutionException: Syntax error"|0x78b85a0a
23:24:18.100 (171981622)|STATEMENT_EXECUTE|[30]
23:24:18.100 (171984170)|STATEMENT_EXECUTE|[31]
23:24:18.100 (172094854)|SYSTEM_METHOD_ENTRY|[31]|System.CalloutException.getStackTraceString()
23:24:18.100 (172209484)|HEAP_ALLOCATE|[31]|Bytes:225
23:24:18.100 (172227288)|SYSTEM_METHOD_EXIT|[31]|System.CalloutException.getStackTraceString()
23:24:18.100 (172258073)|SYSTEM_METHOD_ENTRY|[31]|System.debug(APEX_OBJECT, ANY)
23:24:18.100 (172287801)|USER_DEBUG|[31]|ERROR|Class.HttpCalloutHelper.sendRequest: line 29, column 1
Class.HttpCallout.doPost: line 16, column 1
Class.BoxHttpCalloutService.researchFile: line 115, column 1
AnonymousBlock: line 1, column 1
AnonymousBlock: line 1, column 1

The Blob size is 83237 I know the size is not the problem because Im able to send files 3 or 4 times bigger.

In order to understand what is happening I created following method. Is basically the typical request where as you might guess TEST_BASE64 is the base64 encoded String.

   public static HttpResponse researchFile(){
    HttpResponse result;
    HttpCalloutParams params = new HttpCalloutParams();
    String part1 = TEST_BASE64.substring(0, 67970);
    Blob testBlob = EncodingUtil.base64Decode(part1);
    result = HttpCallout.doPost(BOX_UPLOAD_FILE_OPERATION, params);
    String part2 = TEST_BASE64.substring(67960, 68071);
    testBlob = EncodingUtil.base64Decode(part2);
    params.setPayload(testBlob); //THIS BASICALLY SETS THE REQUEST BODY
    result = HttpCallout.doPost(BOX_UPLOAD_FILE_OPERATION, params);
    return result;

The idea with the code above is find exactly where the code breaks. The idea behind this was that the payload contains something that could be wrong but Im not sure.

If the substring is taken from 0 to 67969 the 2 callouts works. If the substring is taken from 0 to 67970 then first callout breaks (in order to test, I commented the line where I thrown my custom exception so that now to test Im just catching the exception to be able to do both callouts at the same time)

When it works for the last time Im able to catch at the server the following content: ... 38 39 6d a4 8e 1d 1f f7 8e 8c 8d 8f 32 73 43 0c 2c 26 64 93 a9 c3 1f e4 7a a3 f8 fd 93 23 23 e3

The second callout sends correctly (is overlapping on purpose to make sure where is breaking and is breaking at the 7d 7d which is ASCCI code for }

f8 fd 93 23 23 e3 7d 7d 76 f1 9d 44 bc 8d 68 70 80 c1 da 70 24 31 1d 8e 23 b6 6c 69 11 56 ef 07 07 07 bb 2c bd e8 d4 23 a3 9c 2b 3b 18 0a 0f 0e 8f 59 ad 76 d2 13 24 1e 4f b9 3c f4 ad 0e 04 a7 d1 17 8a 48 2c 79 ea 54 de 7f 92 d3 d3 31 74 93 d1 83 d9

I then thought that maybe there are weird situation where you can't start or end a String with } but trying to replicate and get the same exception has not worked. So basically I dont have more ideas right now so help is requested please!.


1 Answer 1


I was able to figure it out. As the hint of the last character was giving it turns out that I had checked by mistake the Allow Formulas in HTTP Body in the Named Credentials definition.

enter image description here

So because I had set that, when it finds the } character, somehow Salesforce tries to merge a formula into the body which of course doesn't exist here so the code fail. Unchecking the value did the trick.

You must log in to answer this question.

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