2

How can I get the body of a file stored in ContentVersion object in salesforce? I've attempted to query its contents but seems that there is no field holding the body value.

SELECT Id,ContentDocumentId,FileExtension,Title,VersionData FROM ContentVersion

I tried using the VersionData field but all its returning is an encoded file data.

2

The VersionData field of ContentVersion contains the base64 encoded data of your csv file.

You will have to decode it using apex code to get comma separated values.

Blob b = EncodingUtil.base64Decode(contentVersionObj.VersionData);
System.debug(b.toString());
| improve this answer | |
0

Probably a late reply, but you don't need to convert it with the EncodingUtil class.

As an example, this is the way to get a csv from a content version:

final ContentVersion cv = [SELECT VersionData FROM ContentVersion WHERE ContentDocumentId = :docId AND IsLatest = true];
final String csvContents = cv.VersionData.toString();
final String[] csvLines = csvContents.split('\n');
| improve this answer | |

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.