How to convert attachments to files in salesforce ?

Poster 2 basic

Scenario

I have uploaded an attachment (salesfiorce_migration_guide.pdf) to an opportunity record from classic salesforce. The uploaded document record has the following actions where ‘view’ action is a link to download the file.

Screen Shot 1940-02-11 at 5.05.59 PM
Uploaded attachments to an opportunity record

Next, uploading another file (router-sample.pdf) to the same opportunity record using upload file functionality in lightning. The uploaded files in the above and current scenario are shown below.

Screen Shot 1940-02-11 at 5.22.26 PM
Uploaded Files & attachment links

You may have noticed that both the files are in PDF format but the recently uploaded file has the pdf icon which we can preview the content without downloading. The other file which is uploaded as an attachment from classic salesforce is treated as a link here.

Therefore, how we can convert the attachments from classic view to files in Salesforce?

Solution

It’s possible to change the attachments to files by enabling a couple of checkboxes in GeneralSettings.

Screen Shot 1940-02-11 at 6.31.33 PM

Why Files?

You can attach a file to the notes & attachments related list of record. The users who have access to the record can see the attached documents. The only way to share the record documents with others is by changing the org’s record sharing rules or posting documents in the chatter feed. Salesforce was trying to solve this in a better way.

Finally, In winter 16 release, Salesforce announced a new related list called files. The benefits of files are

  • Version Control
  • Preview & Options
    • Screen Shot 1940-02-11 at 7.03.27 PM
  • Share with multiple users and records
  • Optimised for lightning
  • Post to chatter 
  • Supports large size

 

The attachments are uploaded in the past cannot be converted as files by enabling the above settings. Run the script given below (script should run by the record owner otherwise it will throw errors). 

Please see the code comments for details.

Note: Salesforce announced that after Winter 18 release, ‘Notes & Attachments’ related list will not have “attach and upload” button.

Poster 2 basic

Don’t forget to share the post if you like it & bookmark the blog for future references.

If you have any comments or doubts on this post, Please comment on the box below.

References

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentversion.htm

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdocumentlink.htm

https://help.salesforce.com/articleView?id=collab_files_overview.htm&type=5

 

Advertisements

One thought on “How to convert attachments to files in salesforce ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s