Thursday, November 7, 2019

How to Convert Salesforce Attachments into Salesforce Files

As now everyone is migrating to Lightning, Salesforce supports files instead of attachment. So while migrating to lightning, we have to convert all attachments to files. Salesforce provide an appexchange app called magic mover for this purpose.

If you don't want to install this app and would like to convert attachments to files, then you can do it with very simple apex script.

I have created a batch class which will convert all attachments related to object (based on query that you pass) to files and you will receive an email with all details once batch job is completed.

Suppose you have to convert all attachments of Contact to files, then use below script:
SK_ConvertAttachmentsToFilesBatch newjob= new SK_ConvertAttachmentsToFilesBatch('select id from Contact');
database.executeBatch(newjob, 1);



I will suggest to run this batch job with minimum batch size (recommended size is 1). Suppose if you run this script with more batch size and one parent record have multiple attachments and attachment size is large, then you may face heap size error in apex script. So it is advisable to run this script with batch size as 1.

Hope this will help!!

No comments:

Post a Comment