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 theContentVersion
.As an example, in one of my orgs I uploaded a file called
App.logo.png
through the API, populating its file name in thePathOnClient
field andApp.logo
in theTitle
field. The system inferredpng
as the value forFileExtension
.