Skip to main content
Free Agentforce workshops and AI Certifications: Learn more. Terms and conditions apply.

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.
    1. Field Label: Number of Days Open
    2. Field Name: Number_Of_Days_Open
    3. Formula Return Type: Number
    4. Decimal Places: 0
    5. 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 Start from Scratch and click Next.
  5. Select Record-Triggered Flow and click Create.
  6. For Object, select Suggestion.
  7. Select A record is created or updated.
  8. For Condition Requirements, select All Conditions Are Met (AND).
  9. For Field, select Implemented_Date__c.
  10. For Operator, select Is Null.
  11. For Value, select $GlobalConstant.False.
  12. For When to Run the Flow for Updated Records, select Only when a record is updated to meet the condition requirements.
  13. For Optimize the Flow for, select Fast Field Updates.

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

Add an Update Records Element 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, click Add Element.
  2. Select Update Records.
  3. Label the new Update Records element as Update Status to Implemented.
  4. For 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 section, for Field, select Status__c.
  7. For Value, select Implemented.
    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 the 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

Comparta sus comentarios sobre Trailhead en la Ayuda de Salesforce.

Nos encantaría conocer su experiencia con Trailhead. Ahora puede acceder al nuevo formulario de comentarios cuando quiera desde el sitio de la Ayuda de Salesforce.

Más información Continuar para compartir comentarios