Skip to main content

Add Business Logic

So far, your app lets employees securely enter and view data about suggestions. That’s pretty cool, but you can make the platform work a little harder for you so that your users don’t have to.

Add a Formula Field

A formula field derives its value from other fields, expressions, or values, saving your users a lot of time. Add a formula field to calculate the number of days from suggestion creation to implementation. Want to learn more about formulas and validations? Earn the Formulas and Validations badge. 

  1. Click the gear icon setup gear and select Setup.
  2. Click the Object Manager tab.
  3. From the list of objects, select Suggestion.
  4. Select the Fields & Relationships from the left navigation, then click New.
  5. For the data type, select Formula and click Next.
  6. Enter the field details.
    • Field Label: Number of Days Open
    • Field Name: Number_Of_Days_Open
    • Formula Return Type: Number
    • Decimal Places: 0
    • Leave all other options as the default.
  1. Click Next.
  2. Click the Advanced Formula tab.
  3. In the Formula Editor, enter the formula: IF(ISBLANK(Implemented_Date__c), TODAY() - DATEVALUE(CreatedDate), Implemented_Date__c - DATEVALUE(CreatedDate)) Completed Formula Options screen.
  4. To ensure there are no errors, Click Check Syntax.
  5. Click Next and Next again.
  6. Click Save.

Add a Validation Rule

Formulas are also used to ensure data quality and enforce business rules. Our employees cannot predict the future, so let’s create a validation rule to make sure that they don’t enter implementation dates that haven’t happened yet. With validation rules, you define the condition for “bad” data. When the system evaluates the rule, it blocks the user from saving the data if the condition is true.

  1. From the list of objects in Object Manager, select Suggestion.
  2. Select Validation Rules, then click New.
  3. Enter the rule details.
    • Rule Name: Date_in_Range
    • Error Condition Formula: Implemented_Date__c > TODAY()
    • Error Message: The implementation date must be today or in the past, not in the future.
    • Error Location: Field: Implemented DateCompleted Validation Rule.
  1. Leave all other options as the default.
  2. Click Save.

Add a Field Update Using Flow Builder

Let’s make it easy on the person who has to act on all the suggestions. When a user adds an implemented date, this automation will automatically update the status to Implemented. Want to learn more about all the automation tools? Complete the Build Flows with Flow Builder trail.

  1. From Setup, click the Home tab.
  2. Enter flow in Quick Find, then select Flows.
  3. Click New Flow.
  4. Select Record-Triggered Flow and click Create.
  5. For Object, enter Suggestion and select Suggestion.
  6. Select A record is created or updated.
  7. Select All Conditions Are Met (AND) from the Condition Requirements dropdown.
  8. In the Field lookup, add Implemented_Date__c.
  9. Ensure Operator lists Is Null.
  10. In the Value lookup, enter False and select $GlobalConstant.False
  11. Select Only when a record is updated to meet the condition requirements in the When to Run the Flow for Updated Records section.
  12. Ensure Fast Field Updates is selected.

The Start element's configuration panel corresponding to the preceding steps.

Add an Action and Activate the Flow

Now add the update triggering record action when the conditions are met. 

  1. On the flow canvas, on the path after the Start element, hover over Add Element and click Add Element.
  2. Select Update Records.
  3. Label the new decision element as Update Status to Implemented.
  4. In the How to Find Records to Update and Set Their Values, ensure Use the suggestion record that triggered the flow is selected.
  5. For Set Filter Conditions, ensure None-Always Update Record is selected.
  6. In the Set Field Values for the Suggestion Record field, add Status__c.
  7. Add Implemented to the Value field.
    The Update Records panel corresponding to the preceding steps.
  8. Click Save in the upper right.
  9. Label your new Flow as Update Status.
  10. Ensure API Name is Update_Status.
  11. Click Save.
  12. Click Activate.
  13. Click the back arrow button  in the upper left to leave Flow Builder.

Try Out the App

Your business logic fires whenever a record is created or updated. 

  1. Go back to a Suggestion record under the Suggestions tab (navigate to the App Launcher and select Suggestion Box).
  2. Enter a date in the Implemented Date field.
  3. Try a date in the future: Did the system block you from saving?
  4. Now try today’s date: The Status field should change to Implemented.New suggestion record with validation rule error.

Resources

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities