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
Vijay NagarathinamVijay Nagarathinam 

String lenght exeeeds exception

Hi,

I am facing string length exceeds limit issue on the below line.

Blob bodyBlob = null;

bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded.substring(0,bodyEncoded.length()-4)+EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)));

How to resolve the string length exceed exception. String length exceeds maximum: 12000000

Thanks,
Vijay
Waqar Hussain SFWaqar Hussain SF
You have to limit the lenght of your bolo value, You can not assign more than 12000000 character to a blob.
Vijay NagarathinamVijay Nagarathinam
Do you know to check the character size???
Waqar Hussain SFWaqar Hussain SF
Yes, You can check the length of the blob by following 
Blob bodyBlob = null;

bodyBlob = EncodingUtil.base64Decode(headerEncoded+bodyEncoded.substring(0,bodyEncoded.length()-4)+EncodingUtil.base64Encode(Blob.valueOf(last4BytesFooter)));

if(bodyBlob.size() < 12000000){
//develop custom logic here
}else{
//throw exception
}


https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_blob.htm
Rahul_kumar123Rahul_kumar123
Hi Vijay,
  • Apparently, there is no way to split files in Salesforce. So sending large files doesn't seem to be possible. You can add this as an idea in "success community" to have the large files split and sent as part of standard API callout transaction. 
  •  I searched around for solutions to pre-determine the length of final base 64 string, here seems to be the valid method of calculating it.Please refer the link below for further reference. 
   
  • Base 64 converted string + the extra SOAP XML should be < 12M for async calls 
  • If we know the how many chars the xml contains then based on the formula given above, the max file size can be determined.

I hope it will be helpful.
  •   Please mark it as solved.so they removed from unanswered questions.and more appear as the proper solution to similar kind of issue.

Best Regards
RahulKumar