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
Anoop ViswambharanAnoop Viswambharan 

System.StringException: String length exceeds maximum: 6000000

Hi Salesforce Gurus,

I am having issue with String length and need some input to proceed further.
I am building an API in which i will be receiving JSON request with some Keys and Values and a big encoded XML string. In my API, i am converting the BLOB request to tostring() for parsing the JSON request.
If the JSON request is less than 6000000 my API works fine. But if it more than 6000000 character i am getting the below error. 

[
  {
    "errorCode": "APEX_ERROR",
    "message": "System.StringException: String length exceeds maximum: 6000000
  }
]
SalesFORCE_enFORCErSalesFORCE_enFORCEr
You can try this method to convert BLOB to string.
public static String blobToString(Blob input, String inCharset){
        String hex = EncodingUtil.convertToHex(input);
        final Integer bytesCount = hex.length() >> 1;
        String[] bytes = new String[bytesCount];
        for(Integer i = 0; i < bytesCount; ++i)
        bytes[i] = hex.mid(i << 1, 2);
        return EncodingUtil.urlDecode('%' + String.join(bytes, '%'), inCharset);
    }