[SalesForce] ContentVersion FileExtension

Does anyone know how I can change the FileExtension for a new ContentVersion in a test class?

Im currently trying to create a test class for my ContentDocumentLink Trigger, in which I have an if depending on the FileExtension of the ContentVersion.
But when creating a ContentVersion I cant fill this field.
When i try to fill it before the insert I just get an error (Field is not writeable: ContentVersion.FileExtension).
I also tried putting the FileExtension in the title, but when testing manually the Title is cut off seperating title and FileExtension.

Best Answer

It's determined by the PathOnClient field as populated when you create the ContentVersion.

As an example, in one of my orgs I uploaded a file called App.logo.png through the API, populating its file name in the PathOnClient field and App.logo in the Title field. The system inferred png as the value for FileExtension.

Related Topic