How to Attach Files to Salesforce Records
In this tutorial we will learn how to use FormCrafts as a Salesforce form builder that automatically creates a new contact record on submit, and attaches uploaded files to that record.
Create a new form
On your FormCrafts dashboard click on New Form. This will open a popup dialog where you can choose to start from a scratch, select a template, or duplicate an existing form. For this tutorial we would select Blank Form. On the next screen enter the form name and press Enter.
We now have to add fields to our form. Using the Add Field button on the top-right corner of the screen add the following fields to your form:
- A one line input field. Label this one What is your last name?
- An email field. Label this one What is your email?
- Add a file upload field. Label this Upload a file
Click on the Salesforce button on the top-left corner of the screen to open the Salesforce sidebar. Now click Connect an organization to connect your organization.
This will be done in three steps.
- Create a new contact in Salesforce.
- Create a new file in Salesforce.
- Associate the file record with the contact record.
Create Contact record
Go to the Records tab and click on Add Action. Select Contact under (select object). Select What is your last name? under (select) and Last Name under (Salesforce field). Click on Add. Follow the same step and map the What is your email? field to Email.
Here is our field mapping:
Create Content version
The file object we would attach to our contact record is called Content Version in Salesforce. On the same Records tab add another action, and select the object as Content Version this time. Click on (select) and pick the file upload field labelled Upload a file. Under (Salesforce field) pick Version Data. Click on Add.
There are other fields and mappings you can add to this object but the only one required right now is the Version Data.
Associating the two
Under Create a Content Version you will notice another option: dependent on. Select SF Contact 1 here. This effectively means that creating a Content Version record is dependent on creating the contact record first. If the contact record creation fails, we also don't want to create the file.
The last step is to associate the Content Version object with the Contact record. Under (select) pick SF Contact 1 and under (Salesforce field) pick First Publish Location ID. Click on Add.
Here is our final field mapping now:
Our form is ready. Click on Preview (top-right) and give it a try. Attached files should appear on the Contact's page under Attachments.