top of page
  • Writer's picturePeter Tikasz

Salesforce Tips #10 - Copying Documents from an Object to another Object


Copying Documents from an Object to another Object

In this video, I will show you how to copy Documents to another Object in Salesforce. You can follow the steps with me, then adapt them to your needs and situation. Visit my website, you will find related videos on various Objects, Documents, Reports and Dashboards.


Now, follow these simple steps on how to copy documents to another object in Salesforce.


Let's get started!


Use Case

It is rather common that some Salesforce users might not have the necessary permissions to access all the Objects (records) in Salesforce (ex: Sales users vs. Finance users). Nevertheless, they still need to have access to some documentation (ex: Signed files). In this post, I will walk through the steps to create an automation that will copy selected files from one Object to another Object.


Logical Steps of the Planned Task

To start with, let’s go through the main steps of the planned task:

Collect data from records of

  • Opportunities

  • Accounts

  • Documents

Loop over the collected Documents, and

  • If there are available documents, collect those which are linked to an Account

  • If not, end the task.

Then

  • Update the triggering object with the collected records.



Completed Flow View

Below is the Flow what I built to automate the planned tasks.


Completed Flow View
Completed Flow View

Now we peek into the details, explaining the Detailed Steps of the task. The Flow will be a Scheduled Flow, where the schedule can be adapted to the needs.


Step 1: Create a Field to Track if a Record has been Processed

First, I create a checkbox on the record.

It will be used to make sure that the record will only be processed once. I named the checkbox field “File Transferred” (API: File_Transferred__c).

I will update this field at the last step of my Scheduled Flow. This checkbox field can also be a picklist type field, if so needed.


Step 2: Get the Primary Object where the Documents are Related to

The first condition in the Flow is to collect all records (in this case on the DocuSign Status Object) where the File_Transferred is “False”.

The second condition is if the Envelope Status field is “Completed”. This second criterion on Envelope Status is not mandatory. It is used to narrow down the number of records to review.





Step 3: Get All Opportunities

This step retrieves all Opportunities where my original Documents are linked to.



Step 4: Get All Accounts

This step retrieves all Accounts where my original Documents are linked to. Note that I am using the lookup of the previous step (Step 3) to locate my Account.

This step is necessary to identify the Object where I want to create a copy of my Documents.



Step 5: Get the Documents

Here we retrieve all the documents linked to my original Object (in Step 1).

LinkedEntityId is the field used in Salesforce to store the lookup value of the record to which the Document is related.

Note that we retrieve All records.




Step 6: Check if there are Documents

This Decision Step narrows down the number of records and will only move forward if Documents were found in the previous step (Step 5).



Step 7: Looping over the Selected Records

Start of the Loop. We want to go over all records collected in Step 5.



Step 8: Create a new Document Record

This step will copy the original file with the “Create Record” component of the Loop.

4 fields need to be completed:

  • ContentDocumentId: the ID of the document

  • LinkeEntityId: the location of the new record (in this case Account Object)

  • ShareType: “V” is for “Viewer”

  • Visibility: “AllUser” as all users should be able to view this record



Step 9: Update Triggering Record

As the last step, the triggering record needs to be updated. This will prevent the same record from being reviewed next time the Scheduled Flow will run.



Note:

Let’s say we want to copy a file named “CompletedDocument1” from an Opportunity record to an Account record.

Let’s suppose that a document named CompletedDocument1 is already in the destination location (Account record).

Normally, when this Schedule Flow runs, it will create a new file. Under the above conditions, this Flow will skip this step as it will not create a duplicate file (with the same name).




You've made it!

If you liked these posts, please click like and subscribe.


Thank you.


Watch the video below.









Comments


bottom of page