I recently came across a requirement for record creation where a couple of scenarios almost made me go for a Lightning Component. Following were some of those scenarios:
- A lookup field must be pre-populated on the UI with the name of the record where the screen is being launched from
- Once the fields on the screen have been filled out, multiple records should be created – all of them being related to each other. This meant that the fields from the related object had to be included on the screen as well.
I went ahead and built a basic Lightning Component but there was one major issue that I ran into. Since it was a custom screen that I created, the matching/duplicate rules around the object records that had to be created did not display the expected behavior. Also, I could foresee a ‘more than needed’ change to the fields on the screen which meant more maintenance with the Lightning Component. So, with a deeper analysis, I decided to give the Quick Action feature a try. Since Quick Action can create records only on one object, I had to add Process Builder to the mix in order to create records across other objects and then establish relationships between all of these records. A tad bit of a downside is that you need to create custom fields on the object where the Quick action resides which would act as helper fields and serve the only function of acting as data-entry points for the related object on the record creation screen. With all of this background, it’s high time we get down to business.
Requirement: Wayne Enterprises uses Account and Contact objects to track its clients and client Contacts. A custom object (Affiliation) is used to establish a relationship between the Contact and Account with field attributes like Role and Start Date. Currently, the creation of Contact and Affiliation is a two step process and the System Administrator would like to have a single screen for data entry which would allow for both Contact and Affiliation object field/(s) input and the corresponding records should be automatically created. This is what should happen after the page is saved:
- Create Contact
- Create Affiliation
- Create the relationship between Contact and Affiliation
A couple of other requirements are:
- The screen can be launched from the Account level
- The screen should auto populate the Account Name on the form as read-only
- The screen should respect all validations including matching/duplicate rules
Solution: We are going to create a quick action at the Account level which would launch an ‘Affiliation Creation’ form. We will first have to create the custom fields on the Contact object that will basically be the fields required to create the related Affiliation. Since quick action cannot have fields from other objects on the page layout, this step is necessary. We will then have to create a Process that creates an Affiliation and links the Affiliation with the newly created Contact.
End Goal: We need a screen like this:
Assuming the two custom fields for Affiliation have been created on the Contact object, let’s first create the Quick Action which will launch the above UI.
Time to build the Process that creates the Affiliation.
Do not forget to activate the Process.
Add the Quick Action to the Account page layout.
And now it’s time to test.
So simple yet useful. Want to see the biggest time saver for going with standard OOTB functionality rather than building a custom Lightning Component for this requirement?
The matching/duplicate rules are respected and work exactly like they do on the standard Contact creation page. Had we built a Lightning Component for this, it would have taken us another 8-10 hours to re-build the matching/duplicate logic for this requirement. I highly recommend using Quick Actions for similar requirements (no URL hacks and we all know why) since they are so much easier to build and maintain.
Have a great week ahead!