Wednesday, March 21, 2018

Salesforce: Call Flow from Action

If you check this blog again Global Actions in Lightning, Action Tyle = Flow only available in Object-Specific action, and not in Global Action. In this blog, we will share how to call Flow from an action, but will not share the basic on how to create action or how to create flow.

Use case: to increase efficiency, business users of Universal Container request the ability to update Number of Employee of Account directly from Opportunity screen.

Solution: create a flow and call it from Action.

1. Create Flow
Make sure the flow must be active and have screens, so it can't be Autolaunched Flow. Flow actions let you pass the value of the record's ID field into the flow, but that's it. Your flow needs to have a variable with Text Input called recordId, the action passes the record's ID into that variable at runtime.

see all items in Explorer panel

1st box - to get Account Id. Remember this Flow will be located in Opportunity so the variable "recordId" will return would be Opportunity Id, not Account Id. In short, this box is to query Account Id from Opportunity object.

2nd box - to get Account Name and Number of Employee. Use Account Id return from 1st query to retrieve Account Name and Number of Employee from Account object.

3rd box - in this box, the user will enter Number of Employees to update into Account, but to make it nicer, we can display Opportunity Id, Account Id, Account Name, and pre-populate Number of Employee in the textbox for user to update.

4th box - this box will save Number of Employee from screen to Account object.

2. Create Action
Create new Action with Action Type = Flow.
Select the Flow created in step 1.
Add the action to "Salesforce Mobile and Lightning Experience Actions" panel in Opportunity Page Layout, in Lightning this action will become a button, while in Salesforce mobile app it will become an icon in action bars.

3. Showtime
Now open an opportunity, you should notice a button called "Update Acct Employee".
Click the button, it will show Account Id, Opportunity Id, Account Name and pre-populate existing Number of Employee from Account.

Lightning Experience

Salesforce mobile app

I am not sure if this is a good use case because you can get something almost similar using action type "Update a Record", check this blog Update Parent Record with Action, but if your screen have logics that need query, or with multiple screens, a single "Update a Record" action will not able to  handle it, calling a Flow from an action would be a better options.

- Update Parent Record with Action
- Global Actions in Lightning
- Flow Action Considerations
- Launch a Flow from an Object-Specific Action

Tuesday, March 20, 2018

Salesforce: Mobile Smart Actions

Mobile smart actions are quick actions that are available for Account, Case, Contact, Lead, Opportunity, custom object page, and also in the global publisher layout. The purpose of this action is only for Salesforce mobile app. Mobile smart actions don’t appear in the full Salesforce site, regardless of which page layouts you add them to, they appear only to users in the Salesforce mobile app.

Mobile smart actions appear as a single action element in the page layout editor. However, they appear as many actions in the action bar in the Salesforce app. The bundle of actions element is varied on each supported object, example: you will see New Opportunity in Account, but not in Contact. You can refer all actions available in Mobile Smart Actions from this document.

You can’t change which actions are included as part of a mobile smart actions bundle, example: you would like to remove New Event action from Case, the solution for this is to remove Mobile Smart Actions, then add the individual actions in the object page layout or Global Publisher layout.

If you have the individual action such as New Task in Salesforce Mobile and Lightning Experience Actions page layout for Account, then you also have Mobile Smart Actions for the same Account layout, New Task will appear twice in the Salesforce mobile app, but only one New Task in Lightning Experience.

New Task appears twice in mobile app

New Task appears only once in Lightning

ReferenceMobile Smart Actions

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.

Tuesday, March 13, 2018

Salesforce: Update Parent Record with Action

Use case: the request is to have the ability to update some fields in parent record object (such as Account) from a child record (such as Contact) page.

Before Lightning (read in Classic), you need to write a visualforce page with apex controller, then add the visualforce page into Contact page layout.

In Ligthning Experience, this becomes much simpler with Lightning Page + Lightning Component + Action, it sounds a lot, but actually, it's very simple, just a few clicks without any script involved. Let's get this started:

1. Create Action in Account
Because we are Account from Contact, the Action must be created in Account.
- Navigate to Setup | Object Manager | Account | Buttons, Links, and Actions
- Click New Action button
- Enter as the screenshot below:

2. Set Action Layout
From the action created, click Edit Layout button, remove default fields added, add fields that you would like the user to update, and click Save button. You can set the fields as Read-Only or Required, even they are not in the object itself page layout.

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

4. Add Component
From Standard components available in the Component panel at the left, drag Related Records component into Lightning Page.

5. Select the Action
Select component added and change the values, change Lookup Field value from "Use This Contact" to "Account Name", then change Update Action with action just created. See screenshot below

6. Showtime
Now, open a contact and check the component added. If you have the permission to update Account, you will be able to update Account fields from here.

Monday, March 12, 2018

Salesforce: Action in Lightning to replace URL Hacks in Classic

In Classic, many of us implemented URL hack, the purpose is to populate a value, example: populate a value from Account field into Opportunity when creating new Opportunity, but also allows the user to change it manually.

But, when switch to Lightning, URL hack will not work. In Lightning, you can implement Action to replace URL hack. Here is the step.

Use Case: to pre-populate Payment Term and Area (both are custom fields) in Opportunity when create Opportunity from Account, both fields are available in Account and Opportunity, although the field type may different.
- Area = Lookup
- Payment Term = Picklist

- Area = Lookup
- Payment Term = Number

1. Create New Action in Account
Because we are creating Opportunity from Account, the Action must be create from Account.
- Navigate to Setup | Object Manager | Account | Buttons, Links, and Actions
- Click New Action button
- Enter as screenshot below (in my Opportunity, I have record type, therefore need to populate).

2. Edit Action Layout
From action created, click Edit Layout, remove default fields added, add both Area and Payment Term, and click Save button.

3. Add Predefined Field Values
Still in Action created, look for Predefined Field Values section and click New button. Select the Opportunity field name, since we have 2 fields to pre-populate, repeat this step twice.
You need to enter formula text, see screenshot below.

4. Add the Action to Account page layout
Still, in Account object manager, click Page Layouts menu, then click the Page Layout name.
Click Mobile & Lightning Actions section, then drag New Opportunity to Salesforce Mobile and Lightning Experience Actions.

5. New Opportunity
Now you should see New Opportunity button when open Account record page.

Click the button and system will popup New Opportunity action window with fields added in action layout. Both fields value should have been populated, and the user also allows to change it too.

One of the drawback when the user creates new opportunities not from the action button, e.g., from New button in Opportunity Related List, the values will be not pre-populated.

Reference: Trailhead: Create Object-Specific Quick Actions

Wednesday, March 7, 2018

Salesforce: List View Mass Action in Lightning Experience

In Spring ’18 release, Salesforce introduces Quick Actions in Lightning Experience on ListView, but only applicable to Case, Lead, and custom objects only. With this user can do mass action on the selected records.

Here is the use case:
Universal Container would like to allow Marketing team to mass update Industry on Lead. Rather than do it one by one, even using inline editing in View, the mass update would be preferred and faster.

Solution: implement Quick action for List View

1. Create New Action
From Setup menu, navigate to Lead object, look for Buttons, Links, and Actions menu.
Click New Action button, enter/select following values:

In some cases, you may need to Predefined Field Values for selected fields for users productivity, but in my use case, it is not required.

2. Add button to layout
Stay in the Lead object, click Search Layouts menu, then select Edit under ListView.
Change Industry should be available under "List View Actions in Lightning Experience"
Select the action and click add arrow button.

3. Lead tab
Click the Lead tab, you need to select a view, such as My Unread Leads, or any list view created, except Recently Viewed. You should see "Change Industry" button, you maybe need to click the arrow button to show more buttons available, this is because it only the first 3 buttons shown on the list page.

4. Select records
Select multiple lead records, up to 200 records from the list view.
Click "Change Industry" button, and select an industry from picklist values, this will update industry from all Leads selected.
Click Save button, and then OK button to confirm.

Now, all Leads selected earlier will be no longer selected and Industry value is updated.