Monday, September 27, 2021

Salesforce Flow Tutorial #3 - What is Record Triggered Flow - Post To Chatter

 In this tutorial we will learn how to create and use Record Triggered Flow. The Record triggered flow can be used to fulfill requirements which requires us to write Trigger in Apex. Record Triggered Flow can be executed when 

  • A record is created
  • A record is updated
  • A record is created or updated
  • A record is deleted.
We can run the flow 
  •  Before the record is saved.
  •  After the record is saved.
Our hypothethical business users requirement is that when a new lead record is created in our Salesforce org, we must post a message to chatter. To handle different types of leads we have different chatter groups. Leads can have rating of Hot,Warm and Cold. 

Here we will learn several new things 

  • A little bit of Chatter
  • Use of Action to post something to chatter
  • Use of Labels in a flow
  • Use of Record Triggered Flow
Chatter - Chatter is a Salesforce real-time collaboration tool that lets your users work together, talk to each other, and share information. You can relate it to Whatsapp, Instagram messenger, etc.

So lets start by first enabling chatter in the org. Check the settings from Setup and make sure that it is enabled.







Once chatter is enabled, search for chatter in App Launcher and open Salesforce Chatter. Once the app opens, open the chatter tab.








Now let us create 3 different public Groups based on the Lead Rating i.e. Hot, Warm and Cold Groups. Different agents/people can be assigned to the public groups to work on these leads. 
Below are the steps to create a Hot Lead Group. You need to create similar groups for Warm and Cold.












Now lets create some labels which we will use in the flow. Search for Label menu item in the setup menu. Labels are used in Salesforce to store configurable Text or any values.



Create a label for "Hot Leads" and provide the Salesforce Group Id of the Hot Leads group in Chatter. You can get the Salesforce Id from the Group URL when you click on the group name in the chatter.


Similarly create the Labels for Warm and Cold Leads. This is how it will be look like once all the labels are created.



Once we have all the configuration and pre-requisite in place, now lets create the flow. Create a new flow and select "Record Triggered Flow" option.



By default this is how the flow will look like. Click on "edit" link.

Make sure that the option "Trigger the flow when" - "A record is created" is selected. And for "Run the flow" we have "After the record is saved" is selected.


Choose lead object by clicking on the "Choose Object" link. Select Lead Object and change the condition so that there is no condition requirement.











Now let us create 3 different text messages that we will post on chatter for Hot,Warm and Cold Lead respectively. Message for Hot Lead is shown below.




Now click on the "+" icon to add a decision element on the canvas. We will configure conditions for "Hot", "Warm" and "Cold" outcomes in the decision box. Here we will simply configure the rating field in the condition. Click on the "+" icon in the decision box to add additional outcomes








 

Now click on the "+" icon in the "Hot Lead?" outcome to add a chatter action.

In the new action box, search for messaging action. When you open the drop down you will see, "Post to Chatter" action. Here we will select the message that we want to post and the Group id, which we configured in the Label. In the Target Name or Id field, you will have to put the group id.





Do the same for Warm and Cold outcomes. After the outcomes are configured, this is how the flow will look like





Now save and activate the flow. To test this flow, we will have to create a new lead record in the org.



Go to the chatter tab, you will see a new message is posted in the chatter group



Salesforce Flow Tutorial #2 - Basic Flow to add two numbers

 In the previous article we have seen how to create a simple "Hello World" type of flow. In case you have not read the article, please take a look here. It is pre-requisite for this article. In this flow we will add 2 numbers, yes 2 numbers :-). Here what the flow does is not important, but the concepts behind the flow needs to be understood.

The purpose of this article is to understand following concepts.

  • Use of variable resource in flows.
  • Use of formula resource.
  • As a bonus, we will learn how to use the debug functionality in flow.


Lets start by creating a new flow using the "New Flow" button. We will use the "Screen Flow" option for this tutorial. In the next screen, select the auto layout option just like we did earlier.


Now lets create a few resources in the flow. Click on the "New Resource" button in the Manager pallete. First create a variable named "firstnumber" with the apiname as "firstnumber", data type as "Number". Set the decimal places to "0"




Now create the second variable resource with api name as "secondnumber", Data type as "number" and with 0 decimal places.

    



Create a formula resource with API name as "sumOutput", data type as "Number" with 0 decimal places.

In the formula box, insert firstnumber with a "+" sign and then the second number.




Now manager toolbox will have all 3 resources listed


Now click "+" in the canvas to add a new Screen Element. Search for the "Number" component. Click it twice to add it on the screen Element. Provide label and API name to the added Number component as shown below. Make both the fields "required".
Provide a label to screen element. Without the label, the flow designer will not allow us to proceed further.









Now click on "+" again to add assignment element


Assign the numnber component input values to the variables we created earlier.




Click "+" again to add a new screen element. Add a number component to this new screen element, so that we can display the output of our addition. Provide a label to the screen element.






Now we will save the flow and debug it. Click on the "Save" button situated on the top right corner.




Provide a name and api name to the flow

Click on debug to start debugging the flow


Select the default options in the screen to start debugging



We will be shown the first screen. Enter any 2 numbers that you would want to add. Debugging output can be viewed on the right hand side of the screen.



On clicking next we will see the output of our addition. In case something goes wrong with the configuration, you will be able to figure it out from the debug logs generated by the flow.



I would highly recommend you to try this very simple flow so that you feel more confident using the flows functionality.

Sunday, September 26, 2021

Hello Salesforce Flows!

 In this article we will learn how to write a simple flow to show the customary "Hello World" message to the user.

Let's start by creating a new flow using the "New Flow" button in the flow list page.



Clicking he "New Flow" button will open the flow builder in a new tab. On this screen you will see options to create different types of flows. For the purpose of this article we will select "Screen Flow" and click on "Next" button.



In the next screen you will get options to select the type of layout that you want to use for creating the flows. You can use either of the options, but I would recommend you to try the "Auto Layout" option which is in Beta at the time of writing of this article. Free-Form layout allows you to place the elements on the screen at any position while the auto-layout has fixed positions. A flow can contain lots of elements and it can grow quite huge in size. A free form layout can look quite messy in such big flows. It can become quite difficult for the person to read and understand the flow in such a situation in case of free form layout.

Next you will be shown a blank canvas screen of flow builder. This is where we will be building our flow.




Click on the "New Resource" button. This option will allow us to create different types of variables , constants, template text etc. Variable is something that can change in a program. This is where we store data in our program which is further manipulated in the flow.


We will see and use the different types of resources in future articles. For the purpose of this article, let us select a resource type of "Variable"

Configure rest of the values as below and click on "Done"

API Name 

strHelloWorld 

Description 

This variable stores text to be displayed on screen 

Data Type 

Text 

Default Value 

Hello World 






Now click on the "+" button shown.



Now you will see options to "Add Elements" to the flow. Below are the options available.


Interaction Elements

  • Screen - Collect information from users who run the flow or show them some information. 
  • Action - Perform an action outside of the flow. Choose from your org’s custom create and update actions or an out-of-the-box action, like Post to Chatter or Submit for Approval. 
  • Subflow - Launch another flow that’s available in your org. 


Logic 

 

  • Assignment - Set Variable Values 
  • Loops - Iterate over a collection of values or records. 
  • Sort - Sort items in a collection. 


Data 

  • Create Records - Create Salesforce records using values from the flow. 
  • Update Records - Update Salesforce records using values from the flow. 
  • Get Records - Find Salesforce records, and store their field values to use later in the flow. 
  • Delete Records - Delete Salesforce records. 

 

 


Since we want to show "Hello World" message to the user, select the screen element.


On the left hand side palette you will see a list of prebuilt components. For now scroll down and select the "text" component. As soon as you click it, that element will be added to the screen element.
Give a label, example - "Hello World". API name will be auto populated. Now in the default value, select our previously created variable - strHelloWorld






Select the header element and enter below details, click on done




Screen element will be added to the flow builder canvas


Now we will save the flow and run it to see the output. Click on "Save" button and provide a name to the flow, API name will be auto populated.





Click on run button after saving the flow.



The flow will be executed, a new tab will show the output of the flow. You can see the "Hello World
 text on the screen.



Congratulations we have just built and run our first flow!


Salesforce Flow Tutorial #3 - What is Record Triggered Flow - Post To Chatter

 In this tutorial we will learn how to create and use Record Triggered Flow. The Record triggered flow can be used to fulfill requirements w...