Skip to main content

Hi everyone,

 

I am currently working on some project for a client, and I need to create a file (.txt) that contains some text.

 

I was currently doing something like this to create the file to an object:

// Generate the file

ContentVersion file = new ContentVersion();

file.Title = fileDisplayName; // Display name of the files

file.VersionData = Blob.valueOf(content); // converting you

file.PathOnClient = fileName; // Name of the file

insert file;

// Link the file to the object

ContentDocumentLink link = new ContentDocumentLink();

link.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id = :file.Id].ContentDocumentId; // Get the ID of the associated ContentDocument

link.LinkedEntityId = id;

link.ShareType = 'V'; // V specify this document is visible to all users, use I for internal users only

insert link;

But during my tests I found something strange:

 

- the file is created and attached to the object in the File category (like expected)

- I can download it

- I can see a miniature of the content of my file (so Salesforce is able to read its content)

 

But I am not able to visualize it Salesforce (see screen bellow)

This file isn't available anymore for .TXT files

 

Do you have an idea of why I can't preview .txt files in salesforce even if Salesforce is able to read it ?

 

 

5 respostas
  1. 1 de mai. de 2023, 14:18

    Thanks to all of you, we finally found the solution, it was due to a secret setting on the Salesforce side that was not turned on (on our client production organisation + development edition).

    We asked the support and they changed it (this setting is not documented anywhere, you have to ask the support to fix it for you)

0/9000