Learning Salesforce Visual Workflow and Process Builder(Second Edition)
上QQ阅读APP看书,第一时间看更新

Hands on 2 - real estate commission calculator

Let's start with an example: Robby Williams is working as a system administrator for Universal Containers. He wants to develop an application using Flow to calculate the commission for real-estate brokers. What he wants, on the very first screen, is to allow real-estate agents to enter the property's value and commission in percentage, and, on the next screen, to display the commission amount. He also wants to make sure that the property value is always greater than 10,000. To develop the Flow, follow these instructions:

  1. Navigate to Setup | Build | Create | Workflow & Approvals | Flows.
  2. Click on the New Flow button; it will open the Flow canvas.
  3. Then navigate to the Palette tab, and drag and drop the Screen element onto the canvas; it will open a Screen element window.
  4. In the Name field, enter Real estate commission calculator; you can also add a description. Under the Navigation Options section, select Don't show Previous button (we don't want to allow users to go back to the previous screen) from the dropdown, check the Show Pause button checkbox, and enter a pause message. A Paused Message window will appear when the user pauses the interview of this Flow. It will look as shown in the following screenshot:     
                 
If you pause the interview, the data that you have entered into the fields on screen gets saved with the interview. So, when you resume later, you can use the data you entered, as long as the values were valid.
  1. If you want to format the pause message, then click on ; it will open the rich text editor. The rich text editor saves the content in an HTML format:
  1. Once you are done, click on the OK button.
  2. The next task is to add fields to the screen. On the Screen element, navigate to the Add a Field tab and double-click on the Currency field, which is available under the INPUTS section, to add it on to the Screen element, as shown in the following screenshot:
  1. On the Screen overlays preview pane, click on the Currency field to configure its settings by entering Label, Unique Name, Input Type, Default Value, and Scale (enter 0), and select the Required checkbox under the General Info section, as shown in the following screenshot:
  1. To make sure that the user always enters a property value greater than 10,000, we have to add a validation rule for it. To do this, navigate to the Input Validation section and select the Validate checkbox, then it will open the formula editor where you can write a validation rule for this field. It also allows you to configure error messages for the validation rule. It will display the error message when the formula evaluates to false.
In Flow, if the formula statement evaluates as true, the input is valid. If the formula statement evaluates as false, the error message is displayed to the user. It means that this is the reverse of a validation rule in Salesforce, where the error message is displayed when the validation rule is TRUE.

The Validation rule allows you to use a standard formula composition in a formula resource, and you can also use it to validate user input in a Screen element. However, a Flow formula doesn't support all functions. A Flow formula can't contain more than 3,000 characters.

The formulas that are not supported by Flow as of the Spring'17 release are GETRECORDIDS, IMAGE, INCLUDE, ISCHANGED, ISNEW, ISPICKVAL, PARENTGROUPVAL, PREVGROUPVAL, PRIORVALUE, REQUIRE SCRIPT, and VLOOKUP. If you use these functions in your formula, it will always return null. A validation rule for the currency field will look as shown in the following screenshot:

  1. On the Screen, add a Number field to allow users to enter Commission in Percentage ( %), as shown in the following screenshot:
  2. The next step is to add a validation rule to this input field:
    1. Add a validation rule so that the user will always enter a commission in percentage greater than zero. To achieve this, use the formula Commission_in_Percentage > 0.00.
    2. You can also configure the help text for the screen under the Help Text section of the Screen element.
  3. Click on the OK button, which is available on the Screen element, to close the Screen element and return to the canvas.
  4. To calculate the commission amount, we have to create a formula. To do that, navigate to the Resources tab and double-click on Formula, which is available under the CREATE NEW section, and create a formula as shown in the following screenshot:
  5. Add {!Property_value} and {!Commission_in_Percentage} to the screen input fields that we created in steps 7 and 10. Once you are done, click on the OK button.
  6. The next task is to display the commission amount on the screen. For this, drag and drop the Screen element from Palette to the canvas. It will open a Screen element window where you have to enter Display Commission amount in the Name field; you can also add a description. Under the Navigation Options section, select Don't show Previous button from the drop-down.
  7. Now navigate to the Add a Field tab, which is available under the Screen element, and double-click on Display Text, which is available under the OUTPUTS section.
  8. In the Screen overlays preview pane, click on the Display Text field to configure the commission amount's settings by entering the Unique Name; to display text from the drop-down, select the formula that we created in step 12. It will look as shown in the following screenshot:
  1. Once done, click on the OK button available in the Screen element.