Box + Salesforce: Flows with metadata

Alex Novotny
Box Developer Blog
Published in
9 min readMar 5, 2024

Its Trailblazer DX 2024 week!

As I previously mentioned in our upcoming events post, Box is sponsoring TrailblazerDX this year. Stop by booth 32 to learn how to extend the value of Box for Salesforce. You’ll also want to check out Box’s session “Supercharge your Content in Salesforce with Box AI & Slack” on March 6th at 1:30pm PT presented by our chief product officer Diego Dugatkin, Nick Read, and myself!

About a year ago, I put out a blog post on using the new Box for Salesforce Flow templates now included in our managed package. If you are wondering what a Salesforce Flow is and how they can supercharge your development — checkout that blog post first.

Today I wanted to show how you can easily add even more Box into your Salesforce experiences by syncing data about a Salesforce record to a metadata template in your Box instance.

Let’s take a look!

What are we building?

For this example, let’s say that any time an opportunity’s stage is updated, we’d like to add/update a metadata value to that opportunity’s folder in Box with the current stage — like needs analysis, closed won, etc. This would allow you to search in Box for all the various stages. So, if you wanted to see all the opportunities in the qualification stage for a particular account without leaving Box, you could!

While I will be showing a pretty simplistic example, this use case could be expanded or edited to meet your custom needs very easily. For example, you could add custom metadata to a specific file based on AI insights or you could add account level information like address, etc to the parent folder and have it cascade down to all future content placed in the folder.

There is a lot that can be done with Box metadata. I’ve always said that metadata is the future of content. I won’t be going over all of it here, but if you want to learn more, please check out our developer documentation on the topic or checkout Rui’s post from last week on Box AI metadata extraction.

Searching with Metadata in Box
Searching results

Prerequisites

This tutorial shows how to implement a custom Box for Salesforce Flow, but in order to follow along, there are some prerequisites that I won’t be going over in this blog.

  • You will need to have followed this guide to install and configure the latest Box for Salesforce managed package. This requires enterprise accounts for both Box and Salesforce. It is highly recommended to test and develop in developer or sandbox environments. If you use a non production instance, you might need to click the use custom url login button in Salesforce.
  • Make sure to follow the instructions in the guide linked above to add the Box lightning component to the opportunity screen.
  • If you already have the managed package installed, visit the installed packages page to confirm your package is on v.4.0 or higher. If not, click here to install the update.
  • If you have already made customizations to your Salesforce instance using APEX triggers and classes, you will need to deprecate that logic. Otherwise, the new flow and your old code will clash.

Walkthrough

Create a metadata template

First, lets go into the Box admin console and create a metadata template for us to place our opportunity’s stage into.

In the admin console, click the content button in the left menu.

Box admin console

Select the metadata tab. Then, click create new.

Box metadata menu

You will see this screen appear.

Create metadata template screen

In order to fill out the fields in the metadata template, you’ll need to know the stages available in Salesforce. Every organization is different, so if your company uses non-default opportunity stages, you will need to go into Salesforce setup to find out what options exist.

Salesforce opportunity stages

Give the metadata template and the field a name by clicking and typing. Select dropdown single select as the format. Then, type in the stages. They stage names must match exactly to the options in Salesforce, including capital letters and punctuation. You’ll have to click add option for each one. Once finished filling out the template, click save.

Box metadata template setup

Now, we have a completed metadata template in Box that we can use in a Salesforce Flow!

Metadata template on an opportunity folder

Create the Salesforce Flow

In Salesforce setup, find the Flows menu and open it.

Search Salesforce setup

Click new flow in the upper right.

Salesforce Flows menu

In the popup, select record triggered flow and click create.

Flow type pop-up

In the object, select opportunity.

Select object type

To configure the trigger, let’s set it to run anytime an opportunity is updated. For entry conditions, make sure to add that the stage name is changed value is true. Check the box to run an asynchronous path, since making Box API calls requires this. Click Save.

Trigger configuration

Under the run asynchronously side, click the little circle plus button. Click the action element.

Add action element

Since we need a folder id to apply the metadata too, we need to select the action to get the Box folder for the specific record that triggered the flow. There could be a situation where the opportunity folder doesn’t exist yet, but don’t worry. The action we use will create one if it doesn’t exist or return the id of the already existing one.

Select the create folder by record id option.

Select create folder for record id

Give the action a label. Doing so will automatically fill out the API name field. For the record id input value field, select the opportunity id. Turn on the create root folder include switch, and select the global constant option of true. Click done.

Action configuration

In order to attach the metadata in Box, we need to create a key value pair to use in a later call to the API. To do this, we will use an assignment element.

Select assignment element

Give the element a label. Then, in the variable drop down, select + new resource. We are going to create two resources to use.

Add a resource

For the first resource, select variable. Name it something like BoxMetadataKVP. The data type should be Apex-defined. The checkbox for allow multiple values should be checked. The Apex class should be box__KeyValuePair. Click Done.

Add a collection of key value pairs

Click the + new resource button again. Select variable. This time name the resource something like BoxMetadataKVPAssignment. The data type and apex class are the same as the first resource, but do not check the allow multiple values option. Click done.

Add an assignment resource for a key value pair

We need to add three rows to the assignment element. First, select the BoxMetadataKVPAssignment resource, and pick the key field. For the operator, select equals. For the value, type stage — all lowercase.

Its important to note, if you didn’t call your Box metadata field “Stage”, this value might be something different. Box metadata templates use camel case. This means the first word is always lowercase, and subsequent words are all uppercase. So, if you named a field Stage for Opportunity, in the value field you’d put “stageForOpportunity.”

Metadata template JSON object
Add key value to assignment resource

Click + add assignment, and select the BoxMetadataKVPAssignment resource. This time, pick the value field. For the operator, select equals. For the value, select the stage field from the opportunity record.

Add value value to assignment resource

Now that we have the stage assigned in a key value pair, we need to add it to the collection resource. Click + add assignment, and select the BoxMetadataKVP resource. For the operator, select add. For the value, select the BoxMetadataKVPAssignment resource.

Add key value assignment resource to KVP collection resource

At this point, so we don’t lose our work, click save in the top right. Provide the flow with a label/name.

Now, add a new APEX action element like you did before.

Add a new action

This time, select the option called create box metadata by folder id.

Select create metadata option

To configure this action, we need a few items. First, type in a label which will also fill out the api name field. For the Box folder id field, select the output folder id from the get opportunity folder action.

Add folder id

Now, for the key/value pairs field, select the BoxMetadataKVP collection resource we created and used earlier.

Add collection resource

Then, type “enterprise” in the scope field, and the key of your Box metadata template in the respective fields. Click done.

Add scope and template key

Quick tip, just like stage field key earlier, the template name also uses camel case. Also, you can find the template key in the url bar of a specific template in the Box admin console.

How to find the metadata template key

The ending flow should look like this. You can click save, and then activate. Let’s test it out!

Final flow

Testing

Open an opportunity that is in the middle of a Sales cycle. Click the mark stage as complete button.

Salesforce opportunity record

Then, view that records Box folder. Mine is in a tab, so I will click that tab. Click the ellipsis, find more actions and then metadata.

Opportunity Box folder

You should now see the stage added/updated in Box.

Metadata attached

And, in Box, if you search based on the metadata template for a stage of Id. Desicion Makers, you’ll see a result appear that matches the folder you see in Salesforce.

Box metadata search

A quick note, sometimes the our metadata system takes up to 15 minutes to index for searching. So, it may take a few minutes for a results to appear.

Box search results

Thanks for checking out this blog on using Box, Salesforce, and Flows! I hope you enjoyed it. Don’t forget, if you are at Trailblazer this week, come see us at Booth 32.

Happy coding!

The above walkthrough shows how to configure the flow for any opportunity record who’s stage is updated, but it won’t work for a brand new opportunity since the conditions listed in the trigger don’t match what happens when an opportunity record is created. This is due to a limitation with the Salesforce Flow options, and Box requiring asynchronous paths. You could make a second flow that is triggered on record create events or add in a custom checkbox similar to what is described here.

Resources

Salesforce Screen Flow Trailhead

Latest version of the Box for Salesforce managed package

Box for Salesforce Installation Guide

Box for Salesforce developer resources

As always, if you have any feedback for the Box Developer Relations team, feel free to drop us a line on the developer forum.

--

--

Alex Novotny
Box Developer Blog

I’m a Box Developer Advocate, helping others learn how to maximize their investment through Box Platform.