Create Attachment
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.
The Create Attachment action requires the following input parameters -
- Resource ID - Folder ID of the newly created folder
- Salesforce Record ID - Account ID of the newly created account
- 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 -
- Resource ID - Folder ID of the newly created folder
- Resource Name - Name of the newly created folder created in the external storage.
- 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.
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 -
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 -
- Resource Id - Id of file or folder.
- Resource Type - Enter “folder” or “file”
- Destination Parameters - Various parameters that specify where the folder must be created
- Library - One of sharepoint, google, onedrive, dropbox, box, cloudfiles.
- Drive Id - Drive Id for SharePoint or Google Drive. This parameter is not needed for other storages.
- 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 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”.
Enter folder or You can get it from “Outputs from CloudFiles: Create Folder” > “Type”.
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 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.
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.
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.
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 -
- Click on App Launcher on top left. Search for the CloudFiles App.
- In the CloudFiles App, select the Content Library Tab.
- Go to your cloud storage. You may need to login if you haven't done so before.
- Go to the target folder where you would like to place the created folders in.
- A dialog box opens up which shows all the IDs. Copy the ID from here.
These steps are shown in the GIF below -
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.
- Id - Id of the created attachment resource
- Destination parameters - Here, the destination parameters refer to those of the resource
- Resource Id - External Id of the Resource
- Path - This is the Cloud storage path of the newly created folder.
- Type - File or folder depending on user
- Name - Name of the resource, with extension in case of files
- Library - External Storage Services like sharepoint, google, onedrive, box, dropbox, cloudfiles
- DriveId - Drive Id in external storage. Only applicable for SharePoint & Google Drive. You can get this value from Content Library
This is the Id of the created attachment resource which denotes the association between record and the external storage service.
Destination Parameters are the parameters of the resource (files/folders) for which the attachment is created.
The external Id of the Resource as in the id of the file/folder.
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 classifies what kind of resource is being used, if it is a folder or a file.
The name of the resource, Using this we can do changes to the initial name of the created resource.
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).
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.
In the gif below, we have shown how we create the attachment and attach the created folder to the Salesforce account record.