How to automatically attach new Notes & Attachments to related records in Salesforce:

Here’s the requirement: when a new Note & Attachment is added to a child record automatically associate it with a related record, too. In this case we’re using PandaDoc on the Order object – when the PandaDoc is completed the Order is automatically ‘Released’ and when the Order is released the completed PandaDoc should attach to the Order AND the related Opportunity. PandaDoc automatically attaches the completed document to it’s related order – this is out of the box functionality. The challenge was relating the completing document to it’s Opportunity, too.

This was easy to accomplish with a flow using the ContentDocumentLink object. Here are the steps:

  • Create a Flow that triggers on, in this case, the Order Object. When Order Status is changed to ‘Released’ trigger the flow.
  • The first Get Records Query in the Flow should check if there’s a ContentDocumentLink where the LinkedEntityID matches the triggering record. This is how we determine if there’s actually a Note & Attachment on this object:
  • Add a Decision element to confirm if there is a ContentDocumentLink. If there is a ContentDocumentLink that means we have a Note & Attachment that should also be shared with the Opportunity so continue the flow. If there is not, just end the flow:
  • If there is a ContentDocumentLink to this parent record, then we just need to create a new ContentDocumentLink where the ContentDocumentID is the record found in the Get Records Query and the new LinkedEntityID is the ID of the related record from the triggering record. In this case the Opportunity ID is already written on the triggering record, but you could add another Get Records query to get related record IDs as needed:

The full flow looks like this – pretty simple: