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.


  1. How can I get around this DML insert limitation such that I can store the content?
  • 6
    The error message says Body__c. Do you have a trigger involved that might be copying the content to another sObject? What's the full stack trace?
    – David Reed
    May 1, 2019 at 12:20
  • @DavidReed no triggers on ContentVersion. I will add more stack trace.
    – Robs
    May 1, 2019 at 12:22

1 Answer 1


@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.