Pages

Wednesday, March 14, 2018

Salesforce: Quick Create Record with Flow

First, this blog is not related to infamous Quick Create record that does not honor validation rules, vote this idea Enforce validation rules on Quick Create records by SteveMo.

In the previous blog Update Parent Record with Action, we shared about using Action to quickly update certain fields of the parent object. This blog is the opposite direction, we would like to quickly create child record from a parent layout, example: create Contact from Account page.

Instead of using Action, for this requirement, I'll use Lightning Page + Lightning Component + Flow, there will be no script involved to build this. Let's get this started:

1. Create Flow
Navigate to Setup, find Flows menu and click New Flow button

(a) Add Variable
Add a variable to capture Account Id, we will pass the Account Id from Account record page. Make sure to select correct Input/Output Type.



(b) Add Screen for Data Entry
Add a screen to capture fields needed, such as First Name, Last Name, and Email. You can set any fields as mandatory fields, and add help text.



(c) Add Record Create item
Add Record Create item to select Object and fields value populated from screen input fields or from variables. In my case, Account Id value will be passed from Account record page to variable Account Id, then to the Record Create item.



(d) Add Screens for success and error handling
You do not want to let your users see the ugly error message, so you can create a screen to display error exception message.

Here is the overall Flow:


Close the Flow and remember to activate it.


2. Edit Account Lightning Page
Navigate to  Setup | Object Manager | Account | Lightning Record Pages.
Click the page, then click Edit button.


3. Add Component
From Standard components available in the Component panel at the left, drag Flow component into Lightning Page.



4. Select the Flow
Select component added and change the values, change Flow value with the Flow created in step-1, notice the variable appeared below and tick Pass record ID into this variable, this will pass {!Record.Id} to the variable name defined in Flow.



5. Showtime
Now, open an Account check the Flow component added. You can add Contact and the contact will automatically link to the Account.



I am not sure if this is a good use case because you can get something almost similar using object-specific Action and add it to the page layout. But, if you have a more complex flow, like involving query to other objects, and multiple screens with different screens, use Flow as Lightning Component will have more impacts.





No comments:

Post a Comment