Getting started with Box for Salesforce development: Part 1
It’s Dreamforce week!
In honor of Box for Salesforce, I thought it would be a great idea to walk through setting up the composite app, as well as show how to make some quick customizations with minimal coding using the developer toolkit.
Let’s go!
Installation Options
Before diving into the demo, let’s wade through the waters of connecting Box and Salesforce.
You have four choices:
- Box for Salesforce composite app (managed package)
- Box for Salesforce developer toolkit
- Box SDK for Salesforce
- Box REST API
Unless your company has a very specific use case, the developer toolkit should solve most customization requirements, but here is a breakdown of the differences.
The composite app (also called the managed package) is the easiest to set up and configure, but it has a fixed folder structure. In the terms of aquatic resemblance, it is like a pond. There’s some water, but not a ton of variance. Permissions in Box match those in Salesforce.
It has gone through Salesforce’s security review in order to be marketed on the Salesforce AppExchange. It also leverages the Box Content Cloud’s admin functionality, frictionless security, compliance, etc.
For more information on the benefits of a composite app, please read The Value of Salesforce AppExchange for Partners.
The developer toolkit allows you to use a list of available methods to customize the composite app or managed package to more fit your needs. These methods are automatically available after installing the app. I compare this to a river. It is a larger body of water that can meander as needed, even creating impressive natural landscapes like The Grand Canyon. Permissions in Box match those in Salesforce.
The Box SDK for Salesforce uses a different installation than the managed package and serves as a full APEX wrapper, allowing you to complete API calls that the developer toolkit doesn’t allow. This resembles a great lake or sea — lots of water with tons of diverse wildlife and activities. Permissions can be fully customizable.
The Box REST API lives separate from Salesforce entirely. This should be used when your problem needs a completely custom solution. I liken this to an ocean. You can develop solutions that are deep and wide ranging but requires high skill from experienced professionals.
To sum everything up, here is a chart that shows the highlights.
Whew! Now, that we’ve finished our water workout for the day, let’s continue on with the tutorial.
The below walks through an example using the developer toolkit. For more advanced use cases using the SDK or API, stay tuned for more content or reach out to our friends at Box Consulting for a custom engagement.
Pre-Requisites
Box and Salesforce instances
This probably goes without saying, but just in case, you need to have Box and Salesforce instances in order to follow this tutorial.
If not, don’t fret! You can sign up for free developer Box and Salesforce orgs at the links provided respectively.
Both give you access to all the features you need to complete this tutorial. I recommend using the developer orgs option if you are new to all of this, and so you don’t make changes to your production environments. Make sure to use a different email address, since you cannot use the same email address in multiple Box instances. I won’t go over the sign up process here, since it is pretty self explanatory.
If you are new to Box, take a look at our Box University courses.
And, similarly, if you are new to Salesforce, I recommend this Trailhead.
Set up users
Once you have the Box and Salesforce instances setup, confirm the following user accounts exist in Box and Salesforce.
- Salesforce admin account — If you went through the Salesforce developer org sign up process above, this is the login you created as part of that. If not, you will need Salesforce administrator login credentials.
- Salesforce user account — This can be any user in your Salesforce instance, including your Salesforce admin. It will get connected to whatever Box user you login to the Box widget with later in the tutorial. I’m going to use the Salesforce admin in this tutorial.
- Box service account — It is advised to create a managed user in Box to own all content created from the Salesforce integration, as well as make all API calls with. You can use the Box primary admin account, but it is not recommended to do so.
- Box user account — This account must be different than the above Box service account. For this tutorial, I’m going to use the Box admin account as the user account. This is the Box account that will get tied to your Salesforce user account upon login to the Box widget.
Install Visual Studio Code
We will be using an extension to deploy our code later. In order to do this, you will want to go ahead and have Visual Studio Code installed. Find the install and instructions here.
After the install is complete, open the program and Install the Salesforce Extensions.
Install Box for Salesforce
- Click the green Get It Now button on the Box for Salesforce app exchange page. If you are not already logged in, it will prompt you to login with a Trailblaze.me account. If you don’t have one already, just go through the signup flow using your Salesforce admin accounts credentials.
2. For the purposes of this demo, I’m going to select install in production, but if you are not using the Salesforce dev org option, you should select install in sandbox.
3. Accept the terms and conditions and click Confirm and Install.
4. If you are not already logged in. you will be redirected to Salesforce to login with the Salesforce admin account credentials.
5. When you reach this screen, make sure Install for Admins Only is selected and click Install.
NOTE — in order to give access to the Box application to other Salesforce users, you will need to apply permissions sets. You can find information on that process here. I’m not going to go over that in this blog post, since it is not needed for the tutorial.
6. Check the box and click Continue. This allows Salesforce to talk to Box on the backend.
7. The installer will run. It takes a few minutes to complete.
You might receive this message. If so, click Done and wait for the email to say the install is complete.
8. Once the install is complete, you should see the package in your installed packages section of setup.
That completes the installation. Onward to configuration!
Configuring Box for Salesforce
- From the app launcher, click View All.
2. Click Box.
3. Click the Box Settings tab.
4. Select Authentication, and then click Connect. Make sure you aren’t already logged into Box in another tab. We want to use the Box service account you set up earlier.
5. Log in to Box using the service account’s credentials. Then, click Grant access to box. If successful, you will be redirected back to the authentication screen.
6. In the Content Settings section of Box settings, type a folder name for all of your company’s Salesforce content to live in. Then, click Save. This will create a folder in Box in the Box service account’s root folder.
While on the Content Settings screen, you will also want to set your Box Enterprise Sub-Domain — if you have one. You can find that by going to the Box admin console > Enterprise Settings > Custom Setup > Company Profile.
Copy the subdomain and paste it into the text box in the Content Settings subdomain field. Click Save.
7. In the Box User Settings section of Box settings, click Connect Account. Then, login to Box using the Box user account from earlier. I’m also going to enable Auto-Collab and seamless login for a better user experience.
At this point, the app is set-up enough for us to move onto coding some custom experiences; however, there are lots of other administration settings and options you can choose for your organization. While I won’t go over them here, you can visit our admin guide to read through those choices. Let’s get coding!
Box for Salesforce Developer Toolkit
Out of the box, the managed package will organize content like the below with each object having its own folder.
But what if we wanted to place all content for a sales prospect under one folder? Let’s walk through how to do that.
Embed Box component in the Accounts page
- In order for users to be able to use Box within Salesforce, we need to add the Box component to the accounts page. Make sure you are logged in with your Salesforce admin account, and visit an account page. Click the gear in the top right, followed by Edit Page.
2. For this example, I’m going to add a Box tab to the middle. Click on the box. Then, click Add Tab.
3. Select Custom in the tab label dropdown. Then, type Box in label text box.
4. In the left components selection section, scroll down and find Box. Click the Box tab in the middle section and drag the component to the place that says “Add Component(s) Here.”
5. Click Save in the top right.
6. Click Activate. Now, a Box tab will appear for anyone who looks at an account page. After clicking activate, you will see a pop up asking if you want to make this an org-wide default.
**REPEAT STEPS 1–6 FOR THE OPPORTUNITY PAGE**
7. When a user visits a record that hasn’t had a Box folder created yet, they will see the below. Clicking Create Folder will make the Box folder for this account.
If a folder has been created already, the user will see the below.
Reminder — If a Salesforce user has access to the account in Salesforce, the Box user connected to it will also have access to the folder from the Box webapp.
Create a custom folder hierarchy
The standard managed package can be setup like above on both standard and custom objects in Salesforce, but like I showed earlier, we can easily customize the folder structure using a tiny bit of APEX code.
For this example, I’m going to show how to create the opportunity folder under the account folder, but this demo can be extended to any number of objects — custom or standard.
Behind the scenes, Box uses something called the FRUP table to maintain the integration. You can find out what is in the FRUP table by running a report, as shown in the instructions here.
For this example we are going to create an APEX trigger that causes an APEX class to run after a record is inserted into the FRUP table — in our case when an opportunity folder is created. When the class runs, it will move the opportunity folder created under the account folder that opportunity is connected to.
Like I mentioned in the pre-requisites, we are going to use the Visual Studio Code Salesforce Extensions to write and deploy our APEX code.
- As part of that, we will use the Salesforce CLI. So, the first step is to install it. Find the installer for your OS here.
2. Confirm the install is complete by running sfdx --version
in a terminal or command prompt. You will see the Salesforce CLI version returned.
3. To access the code snippets we are going to deploy, visit the GitHub page for our Salesforce Examples. You may clone the repository or download a zip. Then, in Visual Studio Code, open up the box-salesforce-demo-101 folder. Note — this is one folder below the root.
4. Open the command palette (view > command palette or use the keyboard shortcut) and type SFDX: Authorize an org
. Hit Enter.
5. Accept the project default. Hit enter.
6. Enter an org alias if you have one. For this example, I don’t, so I’m going to leave it blank. Hit enter.
7. Login to Salesforce using your Salesforce admin account.
8. Allow Access by clicking Allow.
9. If successful, you will see the below pop-up in Visual Studio Code.
10. For this tutorial, you won’t need to make any code changes, but if you want to see the code being deployed, view it below.
11. To deploy the code, open a terminal in Visual Studio Code (Terminal > new terminal or use the keyboard shortcut). Type sfdx force:source:deploy -m ApexClass,ApexTrigger
and hit enter.
If successful, you will see the below pop-up message.
And just like that! — when you create a folder on an opportunity record, it will move that folder under the account for that opportunity.
It may take Salesforce several seconds to auto refresh the Box component. If you want to see results immediately, refresh your page manually
What a journey! I hope you enjoyed this high level overview of getting started with Box for Salesforce development. This is just the tip of the iceberg in terms of what you can do using the integration.
In part two, we will look at editing the two example snippets, as well as go over another common use case: removing the need for a user to click the “Create Folder” button. Stay tuned.
Happy Coding!
Additional Resources
List of Box for Salesforce Developer Toolkit Methods
Creating the Box Sign button in Salesforce guide
…And as always, feel free to post questions on our developer forum.
Special thanks to Kyle Adams, nicholas read, and Randy Johnston!