PREFACE: This post is part of the Zero to Hero series.
The configuration possibilities in Salesforce are endless thanks to custom objects and custom fields. But sometimes, the options can be overwhelming – especially when it comes to creating relationships between objects.
Custom fields are not as scary as they may seem. Today we look at the custom field types that can be created, dissect the difference between a Lookup and Master-Detail relationship, and we go hands-on; building custom fields for our family management app.
Understanding Field Types
Salesforce comes standard with fields on every standard object and it creates “standard” fields on every custom object you create, such as record name, Created By and Last Modified By fields. But these standard fields don’t meet the need of every organization. That is where the use of custom fields comes into play.
On every object, Salesforce provides the ability to create up to 500 custom fields! That is a lot, and that means that the configuration options are limitless. Standard and custom objects can be customized to capture any type of information your business process requires.
Here are a list of the field types that can be created and a description of each. This information is pulled right out of the Help & Training section. You can find the full article and get a printable version of the following table on Help & Training.
[table id=1 /]
Wow! You can see that there are numerous possibilities when it comes to configuring Salesforce and capturing specific types of data.
In addition to the types of fields that can be created, most field types can have their own unique set of field properties. For example, a Picklist field can have up to 300 picklist values with each value being no more than 40 characters. Or, on a percentage field, you can indicate the number of decimal places which should be used when a percentage is entered.
These properties should be evaluated and leveraged to ensure that the data provided is useful and accurate. For example, if a unique alphanumeric ID needs to be captured in Salesforce and the ID is always 8 characters long, update the text field properties so that maximum number of characters is 8. This will prevent users from entering a string longer than the ID the field is intended to capture.
The API name of a field will default to the field name provided except spaces will be replaced with an underscore (_). So, a field by the name of VIN Number would have an API Name of VIN_Number__c.
Notice that there is a double underscore and the letter “c” at the end of the API Name. This appendix indicates that the field is a custom field. In addition to the “c” you’ll also see two additional field appendices: x and r. The x stands for “external” and the “r” indicates a reference field.
The full API name is critical when building formulas, validation rules and integrations.
Lookup vs Master-Detail
These two fields tend to be the most confusing for folks so let’s talk about them for a moment.
Both are relational fields and on the surface, do the same thing. They relate objects to one another. However, there are some fundamental differences between these two relationship field types which need to be considered as part of your solution design.
- Child records must have a parent
- Record level security cascades from the parent to the child records
- Record deletion cascades from the parent to the child records (delete the parent, the child is also deleted)
- Roll-up summary fields can be created on the parent record
- Standard objects cannot be the detail object in the relationship
- A parent isn’t needed, meaning the relationship is optional
- There is no impact to security. Security will be set independent of any related object
- Roll-up summary fields can not be created on lookup fields
Take a look at this great video by John Coppedge of CertifiedOnDemand.com for more details and examples.
Before creating a relationship field, it is important to understand how the objects you want to relate will be used.
Field Best Practices
There are several best practices to consider when creating or managing custom fields in Salesforce.
- When creating a field, try and keep the field label and the API name the same. If a field name needs to change, first validate that the field is not used in an integration. If it is not used in an integration, you can change the API name.
- The Description field is not required, but should always be filled in – especially when the field is being used for a specific purpose (like in an integration).
- Help Text will be displayed to users on the record. Fill this in for every field so that users have an idea of how to use that specific field. It helps with on-boarding and clarification.
- Even though there is a 500 field limit per object, PLEASE don’t create that number of fields. Every field that is created (even when not on the page layout) is available in reporting. Keeping unused fields on the object clutters other areas of Salesforce. Keep it clean and simple.
- When there is a request for a new field, be curious and ask questions. What is this field going to accomplish? Validating these things will ensure that there isn’t an existing field that could be used.
Wow! We have covered a lot of information. Hopefully, you are feeling good and have learned something new. Now that we have all of this great insight into custom fields, let’s create custom fields in our dev orgs to complete our family management application.
If you are following along with Zero to Hero, then you know that last time we created some custom objects to track the details of our Automobiles and Repairs. Let’s create some custom fields to complete those objects. I’ve included the fields and field types to create on each object in the following tables. I’ll walk you through the process of creating a field, then you work on your own to create the remaining fields.
The repairs object is going to be related to two other objects: Accounts and Automobile. The account object contains the repair facility information while the automobile object contains the details of your automobile.
I’ll use a lookup and master-detail relationship to make the associations. I’ve chosen to use the master-detail relationship between the repair and automobile because I want to create a roll-up summary for the cost of all repairs on the automobile record and if the automobile record is deleted, I want the child records (repairs) to also be deleted.
I’ll use the lookup relationship field to relate repairs and the repair shop together because I am not looking to make roll-up summary fields on the account record. You could, however, use a master-detail relationship here instead of a lookup creating a many-to-many relationship.
Let’s walk through the creation of a field on the Repair object.
- In Salesforce, click Setup | Create | Objects | Repairs
- In the Custom Fields & Relationships section, click New
- Choose the appropriate field type. We’ll create the first field Automobiles which is a master-detail relationship. Click the radial button next to Master-Detail Relationship and click Next.
- In the Related To picklist, choose the object that Repairs will be related to. In this case, it will be the Automobile. Choose Automobile from the picklist. Click Next.
- Confirm the field Label and ensure that the Field Name populates by clicking the Tab key on your keyboard.
- Enter a field Description and/or Help Text. Click Next.
- You are now on step 4 of the wizard which is where you’ll indicate who can see this field. Because this is a relationship field and master-detail relationships are required, everyone can see this field. Click Next.
- Step 5 allows you to add the field to a page layout. We only have one page layout which is checked by default. Click Next.
- This next step allows us to add an Automobiles related list to the Repairs object. Select the Repair Facility page layout if not already selected, and click Save.
Complete this process for the remaining fields in the table below. Note that the wizard will not present the same exact steps for each field type.
[table id=3 /]
Now that the fields are created, we’ll modify the page layout so that it is easy to read and navigate.
- In Salesforce, click Setup | Create | Objects | Repairs
- In the Page Layouts section, click Edit to the right of the Repairs page layout.
- Using the drag and drop editor, arrange the fields on the page so that it matches the below image.
- Ensure that the Automobile and Repair Facility fields are required. Do this by hovering over the field and clicking the wrench icon and then checking the box for Required.
- Once the page is arranged to match the above image (or the order you prefer), click Save at the top of the page.
Excellent! The Repairs object is now been completed!
Using the same process you’ve just worked through on the Repairs object, create the following fields on the Automobile object and modify the related page layout.
[table id=2 /]
Great job! You’ve completed the setup of the Automobile object.
Test What You’ve Done
Now that we have the objects and fields created, let’s test what we’ve done and make sure that everything works! First, if you keep your repair receipts, grab one from wherever you keep them and let’s use it to fill in our new records.
- First, let’s create a vehicle record. Navigate to the Automobile tab and click New to create a new record.
- Populate the record with all of the vehicle details. You only really need to do this once so take a moment to find the data for your car.
- Now that the auto record is created, let’s create a repair facility record. Navigate to the tab ribbon at the top of the page and click Accounts.
- Create a repair facility record to include the name, address or phone number from an actual repair invoice. Save the repair record.
- From the Repair Facility record you’ve just created, scroll to the related list section and click New Repair from the Repairs related list.
- Enter the data from your repair receipt. Relate the repair to your newly created Repair Facility and Automobile records.
Awesome! Did it work? Were you able to create the records without any issues? What do you want to change or modify? Feel free to make those changes and test it again!
Resources & Additional Reading
A few weeks ago an Admin Hero reader asked if I could include a section at the end of the Zero to Hero posts with additional information and resources on the topic. I thought it was a great idea, so here are some resources that I think will be helpful to you as you learn about fields and page layouts.
- Object Relationships Overview (Help & Training)
- Considerations for Relationships (Help & Training)
- Creating New Fields in Salesforce (Help & Training)
- Getting Started Using Image Formula Fields (Shell Black)
- Fields & Page Layouts (Shell Black)
- Using Zones When Designing Page Layouts (Shell Black)
How did you do? Are you confused or unable to fully grasp a concept in this post? Leave a comment below and I’ll do my best to provide additional details!