System.DmlException: Insert failed. STRING_TOO_LONG, Body: data value too large

I have a string which has a length of 89308 which represents a PDF document.

I want to store this data into a ContentVersion like this:

ContentVersion contentVersion = new ContentVersion(
    versionData = Blob.valueOf(label),
    title = 'PDF Label',
    pathOnClient = '/Label-' + DateTime.now().getTime() + '.pdf',
    FirstPublishLocationId = relatedID);

insert contentVersion; 

But when I insert the ContentVersion record I get this error:

System.DmlException: Insert failed. First exception on row 2; first error: STRING_TOO_LONG, Body: data value too large: … (max length=32768): [Body__c]

But if I look at the SOAP API reference for ContentVersion it says:

The maximum file size you can upload via the SOAP API is 50 MB.

Which means I can store a lot more than 89308 characters.

And the Field Reference for ContentVersion does not state a limit.

Questions

  1. How can I get around this DML insert limitation such that I can store the content?

Answer

@DavidReed made the key break through – by noticing that the error related to Body__c.

After storing the data into the ContentVersion I was logging the REST request into another object which had a field Body__c which had a max length of 32768, and this was throwing the exception.

Because the content being stored into the ContentVersion and the Log was identical, I did not realise.

mea culpa.

Attribution
Source : Link , Question Author : Robs , Answer Author : Robs

Leave a Comment