I was trying to test my apex class that gets a CSV file, reads it and creates actual records.

In my test class I tried to convert my CSV string into base64 string. Then I used this line of code Blob fileBody = EncodingUtil.base64Decode(body); in order to convert the String body to blob by decoding the base64 string.

Finally, passed it into a contentversion (attached to the object from where my apex reads the CSVs. However, on my query for this CSV within the class I am trying to test, the file type is 'UKNOWN'. The query is: List<el_Bulk_Order_Process__c> bulkOrderList = [select id, el_Request_Type__c,(select id, title, FileType, ContentDocumentId from AttachedContentDocuments order by CreatedDate desc) from el_Bulk_Order_Process__c where id in: bulkOrderProcessIds];

Any ideas? Thank you!

1 Answer 1


When you are creating your test ContentVersion, you should define PathOnClient for FileType to be available.

Also no need to set VersionData with EncodingUtil.base64Decode(body), it would be enough to just set it as Blob.valueOf(body).

insert new ContentVersion(
    PathOnClient = OUTPUT_DOCUMENT_NAME + '.csv', 
    VersionData = Blob.valueOf(body), 
    ContentLocation = 'S'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .