1. Help
  2. Salesforce
  3. Form prefill

Prefill a Form With Salesforce Data

Introduction

Prefilling a form allows you to pre-populate your form with data from Salesforce. This are two ways to prefill a form with Salesforce data:

Static prefill: Prefill data on form load, using URL attribute and a hidden field.

Dynamic prefill: Prefill data based on user input, using Salesforce lookup rules.

Basic setup

On your Formcrafts dashboard click on Add Form → Start from scratch. Enter a Form name and hit enter. This will create a new form.

You can also create a new form by clicking on Add Form → Use a Template and selecting a template. This would allow you to skip this step.

Now add some basic fields to your form using the Add field button on the top-left corner of the form editor:

  1. ID (Hidden)
  2. First name (One line text)
  3. Email (Email)
  4. Salutation (Multiple choice)
Simple Salesforce prefill form

Static prefill

We will prefill contact data by passing the contact ID as a URL attribute. You could then share your form using a link like:

app.formcrafts.com/my-form?ID=0033h00000KzZ3AAAV

Visiting this link will prefill the hidden field labelled ID with the contact ID. Next we will create a lookup that reads the hidden field value and fetches the contact data from Salesforce.

Learn more about using hidden fields and form prefill via URL.

Create a lookup

Click on the Lookups button on the top-left corner of the form editor, and then click on the Add lookup button.

Edit the new lookup, and under (select source) find Salesforce, and click on Connect to Salesforce.

Connect to Salesforce organization

This will open a popup window where you can connect to your Salesforce organization.

Select Object under Lookup type, and then Contact as the Salesforce object. Under Lookup rules map Contact ID to the ID field in your form.

Saleforce contact lookup based on hidden field
Contact lookup based on hidden field

This lookup rule is configured to fetch a Salesforce contact record where the Contact ID (in Salesforce) matches the ID form field (which is a hidden field populated via URL attributes).

Prefill the form

Our form is configured to lookup the record. The last step is to use the values of this lookup to prefill the form fields.

Edit the First name field, and under Prefill value type in @. This will open the references dialog. Find and select First name under Lookup (Salesforce contact).

Saleforce prefill first name field based on lookup
Prefill first name field based on lookup

Do the same for other form fields - Email and Salutation.

Now click on Preview to open the form in a new tab. Edit the URL and add &ID=xxxxxxx at the end, with a valid contact ID. It should prefill the form with the contact data.

Dynamic prefill

In the above example we prefilled the form using data available to us when the form loads, i.e. the contact ID in the URL. We can also prefill the form based on user input.

Add a Contact picklist

Remove the ID field and add a dropdown field to your form titled Select contact. Edit this field and go to the Options tab select the source as Salesforce, and configure this field to fetch contacts from Salesforce:

Simple Salesforce prefill form

This creates a dynamic picklist that fetches contacts from Salesforce. Learn more about dynamic picklists for Salesforce.

Configure the lookup rules

Edit the lookup item created before, and edit the Lookup rules to the following:

Saleforce contact lookup based on picklist
Contact lookup based on picklist

This lookup rule is configured to fetch a Salesforce contact record where the Contact ID (in Salesforce) matches the value of Select contact field in your form.

Now click on Preview to open the form in a new tab. When you select a contact from the dropdown, it should prefill the form with the contact data.