How to Create Field Dependency and Use in Salesforce

In Salesforce, sometimes, while creating records, we need field customization. Like when we select any field, then the other field should show only those values that can relate to that field. This is called field dependency, and it is very useful for data filtration.

In this Salesforce tutorial, we are going to learn about field dependency and its uses in Salesforce. In that, we will see what field dependency is and its uses and where we can use it, and additionally, we will see step-by-step how to create field dependency in Salesforce Lightning and Salesforce Classic.

Field Dependency and Use in Salesforce

What is field dependancy in Salesforce?

In Salesforce, while creating the records, when we select any field then, the other field should show only those values that can relate to that field. This is called field dependency. Using the field dependency, we can save time and quickly create records.

The following are the uses of field dependency:

  • Using field dependency, we can filter dependent field values as per the value that we have selected in the controlling field.
  • This enables the user to narrow down our data and makes it more straightforward to analyze data. It makes our task easier.
  • It is very useful to create records quickly and saves time.
  • It enhances accuracy while creating the records because when we select the controlling field, then in the dependent field, it shows only values that are related to the controlling field.

There are two types of fields which we use in field dependency:

  • Controlling Field: The controlling field decides the behavior of the dependent fields. There are three controlling fields in Salesforce:
    • CheckBox.
    • Standard Picklist.
    • Custom Picklist.
  • Dependant Field: The dependent field shows only those values that are related to the controlling field, the value we can set which value should display according to the controlling field. There are two dependent fields in Salesforce:
    • Custom Picklist.
    • Multiselect Picklist.

How to Create Field Dependency and Use in Salesforce Lightning

Example:

Let’s take an example of the Student Registration Form, let’s consider a student there is an option to select Student Faculty(Computer Science, Commerce, Arts), and after selecting faculty it requires the display of only those Subjects that are relevant to selected Faculty.

See also  How to deactivate global picklist value in Salesforce

Here, we will use a Custom Picklist for student-faculty and a Custom Multiselect Picklist for the subjects.

This can be done using the field dependency, in the next step, we will see practically how to achieve that requirement.

Using the above example and the following steps, we can create filed dependency in Salesforce Lightning.

1. First, log in to Salesforce.org. Then click on the Gare icon, which is on the right side at the top of the corner. Then, you will see the Object Manager tab. Click on it.

Search for the object on which you want to create Field Dependency. Here, I have selected Student_c Object.

Field dependency in Salesforce

2. Then, you can see the Field & Relationship option on the left side of the screen. Click on that, and you will see the fields that you have created. You can see the Field Dependencies button on the right side of the screen. Click on it.

How to create field dependency in Salesforce

3. To create new field dependencies, click on the New button.

Types of field dependency in Salesforce

4. We have already seen which are the Controlling field and Dependent field. According to that, you can select as per your requirements. Then click on the Continue button.

Here, I have selected Student Faculty(Custom Picklist) as the Controlling Field and Subjects(Custom Multiselect Picklist) as the dependent field.

Example of field dependency in Salesforce

5. Here, you can see you have buttons to Include and Exclude the values. At the top of the column, you can see the controlling field in which those values you want to insert. Select those values, then click on the Include button.

Same for the Exclude, if you want to remove a value, select that value and click on the Excule button. After completing this, click on the Save button.

Field dependency example in Salesforce

6. To check if it is applying field dependency, go to the object on which you have created the field dependency and click on the New button to create the record.

Then select any controlling picklist value and see in the dependent field if it is showing the values that you have added.

See also  How to Convert Lookup to Master-Detail in Salesforce

Here, you can see when I have selected Computer Science as the subject then, only the relevant value that I have added while creating the dependencies field is displayed in the dependent field.

Example of field dependency in Salesforce Lightning

7. Here, we can see as I changed the Student-faculty to Commerce, the Subject also got changed. That means as we change the controlling field, the dependent field only shows the values that we have added while creating the field dependency.

Here, we can select multiple values(subjects) because we have used the multi-select picklist as a dependent field.

Field dependency example in Salesforce Lightning

This is how we can create field dependency and use it in Salesforce Lightning.

How to Create Field Dependency and Use in Salesforce Classic

Example:

Suppose there is a custom object Employee_c, in that while creating the records, when the user selects the Country in the controlling field, the relevant States should display in the dependent field.

Here, we will use a Custom Picklist for the Country as well as States.

This can be done by using the field dependencies; in the next step, we will see practically how to achieve that requirement.

Using the above example and the following steps, we can create filed dependency in Salesforce Classic.

1. In Salesforce Classic, click on the Setup button then you will see the + icon which is All Tabs, click on that to see All Tabs.

Example of field dependency in Salesforce Classic

2. In all tabs select the object in which you want to create Field Dependency, here I have selected the custom Employees_c object.

Field dependency example in Salesforce Classic

3. After that you will see an arrow on the right side of the screen, click on that arrow and you can see the View Fields option. Click on it.

Field dependency example in Salesforce Classics

4. Then you can see Standard Fields and Custom Fields & Relationships options, in that here you need to click on the Field Dependency button.

Field dependency in Salesforce Classic

5. After that, click on the New button to create a new field dependency.

Create new field dependency in Salesforce Classic

6. We have already seen which are the Controlling field and Dependent field. According to that, you can select as per your requirements.

Here, I have selected Country(Custom Picklist) as the Controlling Field and State(Custom Picklist) as the dependent field. Then click on the Continue button.

How to create field dependency in Salesforce Classic

7. Here you can see you have buttons to Include and Exclude the values. At the top of the column, you can see the controlling field, in which those values you want to insert, select those values then click on the Include button.

See also  How to Set Default Value for Text Area Field in Salesforce

Same for the Exclude, if you want to remove a value, select that value and click on the Excule button. After completing this, click on the Save button.

Types of field dependency in Salesforce Classic

8. To check if it is applying field dependency, go to the object on which you have created the field dependency and click on the New button to create the record.

Then select the controlling picklist value and see in the dependent field if it is showing the values that you have added.

Here, you can see when I have selected the USA as the Country then, only the relevant value that I have added while creating the dependencies field is displayed in the dependent field.

Apply field dependency in Salesforce Classic

9. Here we can see as I changed the Country to India the States also got changed. That means as we change the controlling field, the dependent field only shows the values that we have added while creating the field dependency.

How to apply field dependency in Salesforce Classic

This is how we can create field dependency and use it in Salesforce Classic.

Conclusion

I hope you have got an idea about field dependency and its uses in Salesforce. In that, we have seen what field dependency is and its uses, types of field dependency, and where we can use it.

Additionally, we have seen step-by-step how to create field dependency in Salesforce Lightning and Salesforce Classic with different examples.

You may like to read: