Pages

Showing posts with label Flow. Show all posts
Showing posts with label Flow. Show all posts

Tuesday, April 19, 2022

Salesforce: Getting Started with Salesforce Flow

Dreamforce 21 announced that Flow is the future of Salesforce, it will replace Workflow and Process Builder and is also friendly for admin without coding background. The flow itself is not something new but it has been added with many features recently, at least can do all workflow and process builder can do.

Here is the business use case: ABC Inc. would like to have a simple "quick create" form that allows users to easily give feedback or idea to enhance the system, from anywhere in Salesforce Lightning, does anyone still in Classic ⚡

Solution: Screen Flow

1. Create a custom object to capture the data

  • Create all the fields needed
  • Add a custom tab if needed
  • Enable the object for reporting, allow activities, track field changes, and allow search
  • Set the object permission by profiles, and fields level security 

2. Create screen flow

Add 3 elements in the flow: screen for form, create records, screen for thank you 


Main screen element, nothing fancy here, just add the input type and set it as required, for this example, type values are derived from a picklist field and set as Picklist Choice Set. You can add emojis to make it fun ðŸ˜Š


Picklist Choice Set gets values from the Type__c custom field.



Create Records element, this is pretty simple, just map each screen component as a value to a field of the object, and remember to select "Use separate resources, and literal values".


** You can add a fault path, in case the system is unable to save the record, such as because of validation rules or etc.


Thank You screen element, the purpose of this screen is simply to tell the user that the data has been captured. In this sample, I will hide the button at the footer.



You can try to debug or run the flow to make sure it will run correctly.

3. Add Flow to Utility Bar

Few items to note here:
  • The flow must be activated
  • Only Screen Flow will be available 
  • Users must have "Flow User" enabled in the user detail, otherwise, the user will not see the flow in the utility item

There is really nothing to be configured here, it is just standard items such as label, icon, panel width, panel height, and of course, the most important is to select the correct flow.

Done and the form looks pretty nice and fits into the utility bar.










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.


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



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.





Friday, January 6, 2017

Salesforce: Workflow Action Failed to Trigger Flow

You build awesome Process Builder or Flow and it works as tested. Few days later, your user start complaining see ugly error as sample below. What is this mean? Is this mean Salesforce buggy, or you have successfully hack it?

Workflow Action Failed to Trigger Flow
The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 30128000000AgZ7. Contact your administrator for help.

Click here to return to the previous page. 


or something like this:

Workflow Action Failed to Trigger Flow
The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 30190000000XmQs. Flow error messages: <b>An unhandled fault has occurred in this flow</b><br>An unhandled fault has occurred while processing the flow. Please contact your system administrator for more information. Contact your administrator for help. 

Click here to return to the previous page.

The one below happened when PB try to call Flow and it fail, it may be caused by the Flow is Inactive, while the one earlier is related to update record fail.

Actually, what here mean is, something is broken with Process Builder or Flow built into your org., it can be fail to update record because of validation rules, error in Flow, or etc.

In our blog earlier, we mentioned that prefix 301 is InteractionDefinitionVersion, but we can't really easily see that record content by putting into URL, or by query with SOQL. So, how to trace that 301 error is referring to which Process Builder or Flow?

The user who create the Process Builder will get email from FlowApplication, with subject "Error Occurred During Flow "flow name", this email will mentioned the flow name, but no Version Id information as in the screenshot above. If the user create that Process Builder not in office, how you can trace Version Id prefix 301 is related to what?

There are 2 options to find this:

1. Flow
Use Flow Designer to check if that Id is refer to which Process Builder or Flow -- remember that Process Builder is using Flow as it engine. Follow this Url https://na3.salesforce.com/designer/designer.apexp#Id=30190000000XmQs, change na3 to your salesforce instance and you should see the Flow Name which is Lead Share for this sample.



2. Workbench
Login to workbench, navigate to menu Info | Metadata Types & Components, select Flow from drop down and click Expand All. You should find that 301 Version Id from the components and get the Flow name, which is "Lead Share"



This is the Process Builder as result of our finding:




ReferenceValidation Rule in Workflow and Process Builder



Tuesday, August 9, 2016

Salesforce: Auto Enable Marketing User

Use Case: some user need to be auto enable with Marketing User in the user detail because they need to add Contact / Lead to Campaign, see this blog for detail.

Solution:
1. Create Auto-launched Flow
2. Create Process Builder

Auto-launched Flow
We need this flow called by Process Builder because field UserPermissionsMarketingUser in User object is not accessible from Process Builder, you need to have a Record Update process with a variable use as input of User Id.

Vote for this idea to allow Process Builder able to access all fields in the object.


Process Builder
With Process Builder on User creation, call above Flow and pass the User Id to that flow.



With simple Process Builder + Auto-launched Flow above, new user created will be have Marketing User auto check, you can add criteria in Process Builder if need to evaluate certain Profile or Role or etc.

Note: deactivate and re-activate user will not effect Marketing User checkbox, so it is not necessary to run the Process Builder on user update.



Tuesday, April 26, 2016

Salesforce: Store Approval Comments to Notes

Use Case: we need to capture Comments type by approver when approve or reject in Approval process as Notes.

Assume that you already have the following:
- Status picklist field: Draft, In Progress, Rejected, Approved
- Approval Process with actions to update status to Rejected or Approved

Solutions:
1. Process Builder 
Process to trigger when the status change to Approved or Rejected

a. Select the object and make sure to select "when a record is created or edited"
b. Criteria: make sure both values captured with OR logic

c. Action: call Flow with passing Record Id as flow variable


2. Autolaunched Flow
Flow designer:

a. Lookup to Process Instance object, filter to Record Id and Approval Process Id, you need to store Approval Process Id into a constant.
Store the result (Id and Status) to a sobject variables, as this will always return only 1 record, we can use Sobject Variables.

b. Lookup to Process Instance Step object, filter to Process Instance Id, Step Status equal to Rejected and Approved. Store the result (Comments, StepStatus, and ActorId) to a sobject Collecton variables, this lookup may return more than 1 record, so we should use Sobject Collection Variables.

c. Loop the Process Instance Step object
Copy each record from Sobject Collection Variables to Sobject Variables.

d. Assign Sobject Variables
Populated fields to a new Sobject Variables.

formulaBody is a formula resource = {!lvProcessInstanceSteps.ActorId} & " | " &
 TEXT({!lvProcessInstanceSteps.StepStatus}) & " | " &
{!lvProcessInstanceSteps.Comments}
Approval Comment is just a text for note title.

e. Assign Sobject Collection Variables
Add Sobject Variables to new Sobject Collection Variables

f. Create Notes


So, when it is approved / rejected, a note will be automatically created.


Here is the notes content:


With slight adjustment in the Flow, you can change the flow to store approval history into a custom object.



Monday, April 25, 2016

Salesforce: Retrieving Metadata with Developer Workbench

Use Case: as time goes by, we have more and more Process Builder calling Auto Launched Flow, we found an Auto Launched Flow and not sure is called by Process Builder.

Solution:
Use Force.com IDE or MavensMate to download the metadata file, but if your machine is not installed with any IDE, you can use Developer Workbench to download the metadata XML file -- huge thanks to Doug Ayers for the tips.

1. Prepare the Package 

A. Using Package XML file
Save the file as package.xml or any other name
 <?xml version="1.0" encoding="UTF-8"?>  
 <Package xmlns="http://soap.sforce.com/2006/04/metadata">  
   <types>  
     <members>*</members>  
     <name>Flow</name>  
   </types>  
   <types>  
     <members>*</members>  
     <name>FlowDefinition</name>  
   </types>  
   <version>36.0</version>  
 </Package>  
** to get the name tag, you can use this free tool Package Builder

B. Create Package
Instead of creating XML file as above, the other option is by creating Package from Salesforce menu Setup | Create | Packages, see this blog for complete reference Getting Unstuck.


2. Developer Workbench
- Click Migration | Retrieve
- Select the XML file created for "Unpackaged Manifest"
- or enter the Package Name, if you use option B - Create Package
- Check "Single Package"

- Click Next button
- Click Retrieve button

- Click "Download ZIP File" link when done


3. Extract and Find
A zip file will be download, you need to extract it and using tool like Notepad++ to find the metadata you need. In my use case as above, I am looking for <actionType>flow</actionType> to find all Flow called by Process Builder.



Reference:

Wednesday, January 20, 2016

Salesforce: Getting Started with Fast Update element using Flow

Use case: business users would like easy and fast way to mass update all Opportunity Type to "New Customer" for a specific Account.

Solution: using Flow to mass update all Opportunity Type based on Account Id provided.

1. Create New Flow
Navigate to Setup | CreateWorkflow & Approvals | Flows
Click "New Flow" button to start building a flow, you will be bring into Flow Designer.

2. Add Screen "Screen Account Id"
- Name the screen
- Add a textbox field to capture Account Id input by user
- Click green arrow icon to set the screen as Start element

3. Add Fast Lookup "Get All Opty"
- Name the fast lookup element
- Query Opportunity with AccountId equal to screen input field
- Create a sObject Collection Variable, object type = Opportunity, here we name it sobjcollvarOptyToUpdate
- Make sure Id field is save to sObject Collection Variable - we need this for update process


- Connect Screen element box to Fast Lookup box, here is how it looks like at this step:


4. Add Loop element "Iterate Each Opty"
- Name the Loop element
- Loop through sObject Collection variable created
- Create a sObject Variable, object type = Opportunity, here we name it sobjvarLoopOpty
- Assign the collection into sObject Variable


- Connect Fast Lookup box to Loop box, here is how it looks like at this step:


5. Add Assignment element "Set Opty Type"
- Name the Assignment element
- Set Opportunity Type to "New Customer" in sObject Variable


- Connect Loop box to Assignment box, choose "for each value in the collection" in the loop routing option.


Here is how it looks like at this step:


6. Add another Assignment element "Copy to New Collection"
- Name the Assignment element
- Assign sObject Variable (with opportunity Type = New Customer) to a new sObject Collection variable
- Create a new sObject Collection variable, here we name it sobjcollvarOptyFinal
- Select operator = Add


- Connect previous Assignment box to this Assignment box
- Connect this Assignment box to Loop element created earlier, this is to loop next record
Here is how it looks like at this step:



7. Add Fast Update element "Update All Opty"
- Name the Fast Update element
- Use latest sObject Collection variable which contain Opportunity Type = New Customer


- Connect Fast Update box to Loop box, when loop done, the flow will continue to do mass update to all Opportunity.
Here is how it looks like at this step:


8. Add Screen "Success" & "Error"
- Success screen just to show a message that all Opportunities has been updated.



- Add another screen to show error message throw if any error occurred on Fast Update process.


- Connect Fast Update box to Success screen box, continue with drag from Fast Update box to Success screen box, it will automatically show FAULT for the link.



Done, this flow can be enhanced as Process Builder + Auto-launched Flow, example: if an Account is marked as bankrupt, all open Opportunities Stage should be change to Closed Lost.


Reference:



Page-level ad