Thursday, August 3, 2023

Automatically Remove Special Characters from Filename while Uploading Files in Salesforce

 As we all know that we can perform URL hack to download all files related to parent record from salesforce. We have observed that sometime downloaded file name is changed to contentversion recordId by salesforce instead of actual file name. 

It is my observation that if file name contains special characters, then when we perform download All, file name is changed to "068xxxxxxxxxxxxxx.pdf".

I have added 2 files to account record for reference:

Now I can generate download URL if I have contentversionId of these 2 files. In my case the download URL will be:


where xxxx is you org domain URL.

You can use below script to generate download all files URL if you know the parent record Id.

If I open this URL, I will zip file which will contain both files and when I will extract it, it will appear as shown below:

As my observation, if any special character is present in file name then salesforce changes the file name. If "-" character is present, then salesforce won't change file name.

For this kind of scenarios, I recommend to have script in place which will remove all special characters from file name whenever file is being uploaded. You can write trigger on contentVersion object to remove special characters from file name. Below is code snippet which can help:

Hope this will help!!!!

No comments:

Post a Comment