Tutorials
Document Management Tutorials
Copy Email Attachments to Case Folders in external storage if Email-to-Case is activated
in this tutorial, we'll guide you on copying case email attachments to corresponding case record's connected folder in any external storage when you have email to case enabled in your org using cloudfiles salesforce integration we will use salesforce flows with cloudfiles flow actions to automatically copy case email attachments into corresponding case folder whenever a new email is recieved what to expect by the end of this tutorial, you can expect to have case folders created in external storage automatically whenever a new case record is created if your org has been enabled to create case records through email to case, then copy the case email attachments into corresponding case folder in external storage the gif below shows the expected output the configurtion for this involves a few salesforce flows with cloudfiles actions in them in the sections below, we cover each of these salesforce flows , the actions used in them and how to configure them pre requisites before you start with the set up, please ensure these steps are completed install cloudfiles in salesforce cloudfiles is available on the salesforce appexchange and can be installed using the standard app installation process check out installation guide docid\ fv1sn qekhvsae njyp6y to know more connect your cloud storage to salesforce using cloudfiles all automations in cloudfiles are activated through salesforce flow builder, utilizing account wide authentication for external storage libraries through a service (admin) user to connect your service user, access the setup, click on the external storage of choice and log into your account for detailed steps, follow automations docid 4nyi6hnqnavp4dbjah tz or refer to the gif below for a clearer understanding set up email to case set up email to case to have salesforce automatically create case records when email messages are sent to the configured support email addresses if you haven't yet, you can follow this set up email to case salesforce help doc add cloudfiles widget to case record page to add the cloudfiles widget to the case record page in salesforce, first, navigate to any case page and click on the "edit page" button once in the lightning builder, insert a new tab and drag and drop the "cloudfiles" widget onto the canvas save the changes and exit the builder refresh the salesforce record page, and the widget should now be visible, allowing easy access to view files and folders within salesforce flow 1 create and attach case folder on new case creation we will create a record triggered flow to automatically create case folder whenever a new case is created this is how the final flow looks like 1 configure the record triggered flow on 'case' object to configure the record triggered flow on the 'case' object, follow these detailed instructions create a new flow and select 'record triggered' as the flow type specify the object as 'case' choose the trigger option 'a record is created' optimize the flow for 'actions and related records' check the 'include asynchronous path' checkbox to enable the 'run asynchronously' path in the flow note in record triggered flows, make sure you run cloudfiles actions only in 'run asynchronously' path refer to the gif below for a visual understanding of this step 2 create case folder using ‘create folder’ action in the 'run asynchronously' path add a create folder action to create case folders at any desired location in connected external storage once you add this action, it will ask you to fill in certain parameters library this is the desired cloud storage where you wish to create the folder input sharepoint for sharepoint, google for google drive, onedrive for onedrive personal & onedrive for business, dropbox for dropbox, box for box, cloudfiles for aws s3 folder name input the folder name you wish to give your created folder here, we input the case number {!$record casenumber} but you can also use a complex text formula if you wish to the next two parameters i e parent folder id and drive id help specify where the target folder should be created e g in sharepoint, which site, drive and parent folder should this folder get created in these parameters can be easily copied from within salesforce using the 'content library' tab on cloudfiles parent folder id this is the cloud drive generated id of the folder where you want to create this folder in drive id this is important for google drive & sharepoint users only these cloud storages offer multiple 'drives' where documents can be uploaded these parameters can be copied by accessing your cloud storage using cloudfiles from within salesforce follow these steps click on app launcher on top left search for the “cloudfiles” app in the cloudfiles app, select the content library tab go to your preferred cloud storage go to the target folder where you would like to place the created folders in click on ‘view metadata’ button as shown below a dialog box opens up which shows all the ids copy the id from here refer to the gif below to get a visual understanding of this step for a detailed description of the create folder action, refer to the create folder docid\ xrardogtcdiogtagjunnl detailed guide this flow action returns various values related to the newly created case folder we will use the newly created folder’s details in the next step to attach it to the case, so that the folder is visible in the case record page's cloudfiles widget 3 attach created case folder to case record using ‘create attachment’ action add a create attachment https //help cloudfiles io/salesforce/create attachment flow action action to attach the created case folder to case record attaching (or associating) our newly created case folder is important since this will enable us to see and operate on the folder contents right from the case record once you add this action, it will ask you to fill in certain parameters “drive id” and “library” parameters will be same as those input in create folder action add the remaining parameters as given below add the parameters as given below resource id input the 'resource id' of the folder to be attached se the output of “create case folder” action as 'create case folder' > id (resource id) resource type input the resorce type of the resource to be attached here, simply enter folder salesforce record id id of the salesforce record case onto which the resource is to be attached here, input the flow triggering case record id i e {!$record id} refer to the gif below to get a visual understanding of this step 4 save and activate the flow once the flow is activated, for every new case record created, this flow automatically creates a case folder in the external storage at the desired location and attaches it to the case record flow 2 copy case email attachments to case folder on new email message we will create a record triggered flow on email message object to automatically copy email attachments into corresponding case fold er this is how the final flow looks like 1 configure the record triggered flow on 'email message' object to configure the record triggered flow on the 'email message' object, follow these detailed instructions create a new flow and select 'record triggered' as the flow type specify the object as 'email message' choose the trigger option 'a record is created' set the entry conditions, to trigger the flow only when the email message has files attached to it for this, select 'condition requirements' as 'all conditions are met (and) set the single condition, with field as 'hasattachment', operator as 'equals' and value as 'true' optimize the flow for 'actions and related records' check the 'include asynchronous path' checkbox to enable the 'run asynchronously' path in the flow note in record triggered flows, make sure you run cloudfiles actions only in 'run asynchronously' path refer to the gif below to get a visual understanding of this step 2 get 'content document link' records linked to the email message in the 'run asynchronously' path add a 'get records' element to output all the 'content document link' records linked to the 'email message' that triggered the flow refer to the gif below to get a visual understanding of this step this element outputs a 'content document link record collection' with all the records associated with the flow triggering email message record the output of this element shall be used in subsequent elements of the flow 3 add a pause element to ensure case folder creation add a ' cloudfiles delay ' apex action into the flow, positioned after the 'get records' element and before retrieving details of the corresponding case folder in the subsequent action the 'cloudfiles delay' apex action functions as a 'pause for a given time' element before the flow proceeds to execute the next action or element the execution of "flow 1", responsible for case folder creation and attachment, may encounter delays to prevent flow errors when fetching case folder details before the completion of "flow 1", this delay element is incorporated into the flow once you add the 'cloudfiles delay' apex action, it will ask you to fill in a single parameter delay(milli seconds) the amount of time the pause acts for in milliseconds refer to the gif below to get a visual understanding of this step note avoid setting a long pause duration as it may result in flow timeouts and errors for this specific flow, a delay of 10,000 15,000 milliseconds should suffice 4 get case folder of the email message's corresponding case add a get connected folder docid iq8rljf2ne8sx0 iuu apex action to output the details of corresponding case record's folder once you add the action, it will ask you to fill in a single parameter parentid input the salesforce record id whose connected folder is to fetched here, input the flow triggering email message record's case id as 'record' > 'case id' i e {!$record parentid} refer to the gif below to get a visual understanding of this step in case the salesforce record has got a single folder attached to it, then get connected folder docid iq8rljf2ne8sx0 iuu outputs the attached folder details 5 gather the content document ids of all attachments to be copied add a 'loop' element and set it to loop through the 'content document link record collection' output by the 'get email attachments' element for each 'content document link' in the loop, with an 'assignment' element, add its corresponding 'content document id' to a text collection variable after the end of the loop, the text collection variable will contain all the content document ids of the email attachments refer to the gif below to get a visual understanding of this step 6 copy the email attachments' content documents to the case folder add a copy salesforce files docid\ xaoztzqon8utm7hyzn bg apex action to copy the email attachments to the fetched case folder once you add this action, it will ask you to fill in certain parameters add the parameters as given below content document ids input the content document id collection which are to be copied here, input the content document id collection gathered by the loop driveid input the copy destination's drive id (only for sharepoint and google drive) here, input the 'drive id' of case folder output by 'get case folder' action folder id input the copy destination's folder id here, input the 'folder id' of case folder output by 'get case folder' action library input he copy destination's cloud storage input sharepoint for sharepoint, google for google drive, onedrive for onedrive personal & onedrive for business, dropbox for dropbox, box for box, cloudfiles for aws s3 you can even use the outputs of the 'get case folder' action here, input the cloud storage or use 'library' output by 'get case folder' action salesforce record id (optional) optionally input the record id from which the files will be copied here, optionally input the email message id from which the files will be copied note the 'content document ids' parameter only accepts a text collection as a valid input even if you have only one content document id, you must input it as a text collection refer to the gif below to get a visual understanding of this step 7 save and activate the flow once the flow is activated, for every new email received , this flow automatically copies the email attachments to case folder attached to respective case record test the flows in action now that everything is setup, lets test our flows follow the steps below to see this automation in action to create a case, send an email to email address used in email to case setup attach a few files to this email these can be any type or size of files open the created case it may take upto a minute for the case to get created by email to case functionality within the cloudfiles widget on case record page find an automatically created case folder in the configured external storage find all the email attachments copied into the case folder flow execution and folder creation may take some time (a few seconds to a minute) if you don't see any changes, try refreshing the cloudfiles widget a couple of times congratulations! you've successfully configured flows to automatically create case folders for new case records and copy case email attachments to their respective case folder in external storage