Salesforce Picklist Options

Syncing dropdown field options with the picklist values of a Salesforce object's properties

Step 1:

Create a dropdown field with no options and is disabled by default

  1. Navigate to your form's designer

  2. Add a new dropdown field and give it an id.

  3. Set its properties to Readonly, and remove the default options it has.

Dropdown field

Step 2:

Create an API Connector that fetches the Salesforce object

  1. Navigate to the logic page for your form.

  2. Under the "API Connectors" tab, press Create API Connector

  3. Choose "Custom Connector" and hit Next

  4. Fill out the API Connector to correspond with your needs.

    1. Use this url, but fill in your Salesforce instance url and object name: https://<YOUR_SALESFORCE_URL>/services/data/v50.0/sobjects/<YOUR_SALESFORCE_OBJECT>/describe

    2. Add a "Authorization" header with the value "Bearer {{salesforce_token}}"

      1. This will prompt you to choose a connected Salesforce Account to use

  5. Hit Next and Skip

API Connector

Step 3:

Create a Logic rule that uses the API Connector to set a field's options

  1. Under the "Rules" tab, press Create Rule

  2. Set the Trigger to "Form Step is Loaded" and choose the step to run the rule on

  3. Switch the rule to Advanced Logic and press edit code

  4. Paste this code in and change Industry to the Salesforce Object field name you want, and sf_industry_dropdown to the Field ID of your dropdown field.

function setPicklistOptions(sf_fields, sf_field_name, feathery_field_name) {
  const sf_field = sf_fields.find(field => field.name === sf_field_name);
  if (!sf_field) {
    throw new Error("Could not find the Salesforce field!")
  }
  
  const picklist_values = sf_field.picklistValues;
  const options = picklist_values.map(option => option.value)
  
  feathery.fields[feathery_field_name].options = options;
  feathery.fields[feathery_field_name].disabled = false;
}

try {
  const response = await feathery.http.connect("Salesforce Describe Object");
  const fields = response.data.fields;
  
  setPicklistOptions(fields, "Industry", "sf_industry_dropdown");
  // Call setPicklistOptions() for more fields here
} catch (error) {
  console.log(error.message)
}

You can populate multiple dropdown options by modifying the above code. You can call the setPicklistOptions function multiple times, once for each dropdown.

Result:

Now the dropdown options are pulled from Salesforce automatically, when the step is loaded.

Last updated

Was this helpful?