Flow Actions

Create Attachment

Introduction

The Create Attachment action is a way to attach a file or folder to a Salesforce record. Files & Folders attached to a record show up in the CloudFiles widget on the record page in Salesforce. The image illustrates a flow example demonstrating how to create an attachment and set the input values. Detailed descriptions of these parameters are provided in the following section.

Document image


The Create Attachment action requires the following input parameters -

  1. Resource ID - Folder ID of the newly created folder
  2. Salesforce Record ID - Account ID of the newly created account
  3. Destination parameters - Various parameters that specify details of the attachment created on the record.

This action doesnt give any output parameter but we can still obtain them by adding “.resource” and we can get various parameters of the created folder earlier as the output -

  1. Resource ID - Folder ID of the newly created folder
  2. Resource Name - Name of the newly created folder created in the external storage.
  3. Other parameters - Parameters specifying the location of created resource in the external storage.

In this article we show how to add this action to your flow and configure the parameters.

What this action does

The Create Attachment action enables you to link files or folders to a Salesforce record, making them visible in the CloudFiles widget on the record page. For example, if you create a folder hierarchy for an account object, you can use this action to access these folders directly within Salesforce, eliminating the need to switch between Salesforce and external storage. Below is an example of an attached folder -

Document image


Input Parameters

In your flow builder, search for the element named "CloudFiles: Create Attachment". You can also find this action in the CloudFiles category when you click "action" element in "Add Element" box. Select the action to insert it into the flow. And then do the configuration of the input parameters. Here is a list of all input parameters. For details, check out the individual sections below -

  1. Resource Id - Id of file or folder.
  2. Resource Type - Enter “folder” or “file”
  3. Destination Parameters - Various parameters that specify where the folder must be created
    1. Library - One of sharepoint, google, onedrive, dropbox, box, cloudfiles.
    2. Drive Id - Drive Id for SharePoint or Google Drive. This parameter is not needed for other storages.
    3. Salesforce Record Id - Id of the Salesforce record. In a record triggered flow, this would be “{!$Record.Id}” or “Triggering Account” > “Account ID”

Resource Id

Resource ID is the ID of the file/folder. You can get it from one of the earlier actions in flow like "Outputs from CloudFiles: Create Folder" > “Resource Id”.

Resource Type

Enter folder or You can get it from “Outputs from CloudFiles: Create Folder” > “Type”.

Destination Parameters

These parameters help specify where the target folder should be created. There are multiple parameters that may need to be set based on the target cloud storage such as library, drive ID, parent folder ID etc... E.g. sharepoint users require all 3 while dropbox users may require only one.

These parameters can be easily copied from within Salesforce using the Content Library Tab. Below we describe these parameters and then we show how to copy them easily with a single click.

Library

Library is the desired Cloud based drive where you wish to create the folder. This is a simple text field and you can enter one of these options - sharepoint, google, onedrive, dropbox, box, cloudfiles (for AWS S3).

It's best to copy this parameter from the dialog box as shown below.

Parent Folder ID

This is the cloud drive generated ID of the folder where you want to create this folder in. This can be grabbed from the metadata dialog as shown below.

Drive ID

This is important for google drive & sharepoint users only. These cloud storages offer multiple 'drives' where documents can be uploaded. Drive ID can be copied form the metadata dialog as shown below.

Document image


These parameters can be obtained within Salesforce with a single click by navigating to the parent folder in the Content Library Tab and clicking the "View Metadata" button as shown in image below. The Content Library Tab can be accessed from the CloudFiles App Launcher or an also be inserted onto any of your standard or custom apps.

Follow the steps below to retrieve these IDs -

  1. Click on App Launcher on top left. Search for the CloudFiles App.
  2. In the CloudFiles App, select the Content Library Tab.
  3. Go to your cloud storage. You may need to login if you haven't done so before.
  4. Go to the target folder where you would like to place the created folders in.
  5. A dialog box opens up which shows all the IDs. Copy the ID from here.

These steps are shown in the GIF below -

Document image


Output Parameters

The Apex action returns a custom type called Attachment. The output parameters are the “attachment id” and the “Resource” parameters. You can use fields from this type, like id, name etc. You can use these fields in subsequent flow actions or save them as custom fields on record to use outside this flow.

  1. Id - Id of the created attachment resource
  2. Destination parameters - Here, the destination parameters refer to those of the resource
    1. Resource Id - External Id of the Resource
    2. Path - This is the Cloud storage path of the newly created folder.
    3. Type - File or folder depending on user
    4. Name - Name of the resource, with extension in case of files
    5. Library - External Storage Services like sharepoint, google, onedrive, box, dropbox, cloudfiles
    6. DriveId - Drive Id in external storage. Only applicable for SharePoint & Google Drive. You can get this value from Content Library

Id

This is the Id of the created attachment resource which denotes the association between record and the external storage service.

Destination Parameters

Destination Parameters are the parameters of the resource (files/folders) for which the attachment is created.

Resource ID

The external Id of the Resource as in the id of the file/folder.

Resource Path

This is the Cloud storage path of the newly created resource. Path cannot be changed to make changed we need to do further actions like “copy resource” or “move resource

Type

Type classifies what kind of resource is being used, if it is a folder or a file.

Name

The name of the resource, Using this we can do changes to the initial name of the created resource.

Library

Library is the desired Cloud based drive where you created the folder. This is a simple text field and you can enter one of these options - sharepoint, google, onedrive, dropbox, box, cloudfiles (for AWS S3).

Drive ID

This is important for google drive & sharepoint users only. These cloud storages offer multiple 'drives' where documents can be uploaded.

The image below shows the output of the create attachment apex action.

Document image


See it in action

In the gif below, we have shown how we create the attachment and attach the created folder to the Salesforce account record.

Document image