Append images to a Rich Text field using a Flow (Admin-Oriented)

This article demonstrates how to append images to a Rich Text field using a Flow.

Pre-requirements:

For this demo, you should ensure that the SharinPix Image Sync feature is activated for the object you intend to use. For more information on how to set up the Image Sync, you can refer to the following article: Setup SharinPix Image Sync

In the following sections, we will use the Account object and configure automations that will append images to a Rich Text whenever an Account record's type is changed to a specific value using the SharinPix Apex class, SharinPixToRichTextAutomation. To do so, we will use:

  • a Flow

The Apex class, SharinPixToRichTextAutomation , provides several fields that can be used to parametrized the Rich Text. The table below provides more details for each field:

Field Name | Description | Is Field Value Mandatory?

---|---|--- Record ID | The current record ID. | Yes Rich Text Field API Name | The API name of target Rich Text field. | Yes Image URL Field API Name | The API name of the image URL field. Some available values are: sharinpix__ImageURLFull__c ,** ** sharinpix__ImageURLOriginal__c ,** sharinpix__ImageURLThumbnail__c** ,** sharinpix__ImageURLMini__c** You can also create a custom image URL field on the SharinPix Image object. | Yes List of Image Public IDs | The list of public IDs of images to be included in the Rich Text field. If no value is provided for this field, all images available on the record's album will be included in the Rich Text field. | No Replace Rich Text Area Content | When value is set to true , the existing content of target Rich Text Area will be replaced. | No Image Caption Text | The API name of the field containing the text to be displayed alongside the image. Some accepted values here are any API name of Text fields available for the SharinPix Image object such as Name , sharinpix__Title__c or T****itle & Description. | No Number of Columns | The number of columns to be included in the Rich Text field. The default column value is 1 and the accepted value ranges from 1 to 10 columns. | No

The SharinPix package includes the Apex class SharinPixToRichTextAutomation** ** which is used in Flows to append images to a Rich Text field.

Please note that this class is available in package version 1.194 and above. If your SharinPix package has an older version, you should can refer to the following article to update the same:

How to update SharinPix package from the AppExchange?

Creation of the Flow

This section demonstrates how to create a Flow that invokes the Apex class SharinPixToRichTextAutomation to append images to a specific Rich Text field.

To do so, follow the steps below:

  • On the Account object, create a new Rich Text field named **Images **(You can skip this step if you have already created the field in the previous section)

  • Go to Setup. In the Quick Find Box, type Flow

  • Under Process Automation , select Flows

  • Click on the button **New Flow **located on the top right corner

  • Select **Record-Triggered Flow **as the Flow type

  • Once on the Flow builder, click on the Edit link located in the Start element

  • For the, Trigger the Flow When , section, select A record is updated

  • For the, Run the Flow section , select After the record is saved

  • Next, click on the **Choose Object **button located on the **Start **element, then

    1. Choose **Account **as the object

    2. Leave the Condition Requirements section as After the record is saved

    3. Next, choose Type as the field , Equals as the operator and** Customer - Channe****l** as the value

    4. For the When to Run the Flow for Updated Records section, select Only when a record is updated to meet the condition requirements

    5. Click on **Done **to apply the changes

  • Then, go to the Manager tab and click on the **New Resource **button to create a variable as follows:

    1. For the variable, select **Variable **as the Resource Type

    2. Enter **recordId **as the API Name

    3. Select **Text **as the Data Type

    4. For the Availability Outside the Flow section, select Available for input

    5. Click Done to save

Next, drag and drop an **Assignment **element onto the canvas. For this element, enter the following details:

  1. Enter **Assign Record ID **as the label

  2. In the Set Variable Values section, enter recordId as the Variable, Equals as the operator and for the value, click on **$Record__Prior **followed by Id

  3. Click on Done to save

  • Connect the Assignment element to the Start element

  • Next, drag and drop an **Action **element

  • In the Action search bar, search for sharinpix__SharinPixToRichTextAutomation** **

  • Enter Append images to Rich Text** ** for the label

  • In the Set Input Values , configure the fields as follows:

    1. For the field Image URL Field API Name , enter the desired image URL field's API name. For this example, the field sharinpix__ImageURLThumbnail__c was used

    2. For the field Record** ID**, choose the variable recordId

    3. For the field Rich Text Field API Name , enter the desired Rich Text field API name. In this case it is Images__c

The fields Image URL Field API Name , **Rich Text Field API Name and Record ID ** are mandatory and therefore, should always be provided with a value.

There are 4 additional non-mandatory fields which are also provided by the SharinPixToRichTextAutomation** ** Apex class. You will find more information regarding these fields in the table available at the beginning of this article.

Let's add some of them by selecting the **Include **button and entering the required values as follows:

  • For the Image Caption Text field, enter Name

  • For the field, Number of Columns , enter the value 2

  • For the Replace Rich Text Area Content , select {!$GlobalConstant.True}

  • Click Done to save

Tips:

  • In the above example, we did not specify a list of pre-defined images to be appended to the Rich text. In this case, all images uploaded onto the record's album will be appended to the Rich Text by default.

  • Contrary to Process Builders, Salesforce Flows also allow you to filter the images you want to add to the Rich Text. For example, if you only want SharinPix images having the png format to be appended, you can set up the Flow in such a way to store these images in a **Collection Variable **and pass the same variable as the value for the **List of Image Public IDs **field

  • Connect the Action element to the Assignment element before saving and activating your Flow

Demo

To test the Flow:

  • Go on an Account record

  • In the record's Details section, change of the value of the field Type to **Customer - Channel ** to append the images to the Rich Text field

  • Check if the Rich Text field, Images , has been populated accordingly:

Last updated