Copy Salesforce files to SharePoint
- When a file is uploaded to Salesforce native storage, copy it to SharePoint. Files can be uploaded to Salesforce native storage from "Files" or "Notes & Attachments" section. Files can also be uploaded by other means like Email-to-Case or apex code
- Delete the original Salesforce file & replace it with a link of SharePoint file
The Same flow can be used with other cloud storages like Google Drive, OneDrive, Box, Dropbox, AWS s3. Just replace the library type sharepoint in configuration parameters with the desired library name.
Salesforce stores files as ContentDocument object. The actual binary data to file is stored as ContentVersion. A ContentDocument can have many ContentVersion objects linked to it. a ContentDocument is associated to a Salesforce record using a junction object called ContentDocumentLink
The fields of interest on the ContentDocumentLink object are -
- LinkedEntityId - Id of the Salesforce record on which file is uploaded
- ContentDocumentId - Id of the ContentDocument for the file
For our use case, we would want to trigger a flow on ContentDocumentLink creation. However, Salesforce doesn't let us setup a "Record Triggered Flow" on ContentDocumentLink object.
To solve this issue, CloudFiles provides a platform event called Salesforce File Attached Event. We can setup our flow on this platform event.
The final flow would consist of following elements -

- Decision element, to continue only if the CloudFiles event is of type Salesforce File Attached Event. You can optionally filter the flow to continue only when file upload is on certain objects like Account, Opportunity etc by filtering on event's object type


- A decision element to check the existence of connected folder to avoid any errors

Next, we want to delete the original Salesforce files after file is copied successfully and replace it with a SharePoint link. Since the file copy happens asynchronously, CloudFiles publishes another event named Salesforce File Copied Event. We will setup another flow on this event to delete the original file from Salesforce and replace it with a SharePoint link
The final flow would consist of following elements -
- Decision element, to continue only if the CloudFiles event is of type Salesforce File Copied Event


- Delete the original Salesforce file
