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

Add Business Logic

Accessibility

This unit requires some additional instructions for screen reader users. To access a detailed screen reader version of this unit, click the link below.

Open Trailhead screen reader instructions.

So now you have your basic app in place, and users can maintain data and manage the project. However, there are some business rules for these types of projects that you can put into place, too.

Building a Space Station is not all sunshine, rainbows, and shooting stars. It’s hard work that has to be done right. Consider the past problems with exhaust ports. There are too many of them, and they are, apparently, very vulnerable to mischief. 

Prevent those pesky troublemakers from causing problems again by fully staffing your project with enough Exhaust Port Inspectors to catch unsecured exhaust ports. The Exhaust Port Inspectors need to put in enough time on each project, even including putting in overtime hours. 

You need to create a validation rule that prevents users from saving a record for an Exhaust Port Inspector if the utilization is less than 150%. 

Add a Utilization Validation Rule

  1. Click setup icon and select Setup, then click the Object Manager tab next to Home.
  2. Click Resource.
  3. Select Validation Rules from the left navigation.
  4. Click New.
  5. For the Rule Name enter: Inspectors_Must_Work_Overtime
  6. For the Error Condition Formula, you want to prevent the record from being saved for an Exhaust Port Inspector with a utilization of less than 150%. Enter the formula as AND(Name = "Exhaust Port Inspector", Utilization__c < 1.5).
  7. Click Check Syntax to make sure the formula has the correct syntax.
  8. For the Error Message enter: Exhaust Port Inspectors must work at least 150%. No coffee breaks!
  9. For the Error Location click the Field radio button and then select the Utilization field.
    Completed validation rule with error condition formula and error message.
  10. Click Save.

Now go back to your Space Station record and enter a new resource type of  Exhaust Port Inspector with a utilization less than 150. You should now see an error message preventing users from entering bad data.

Automate with Flow Builder

Flow Builder is a tool that helps you easily automate your business processes by providing a powerful and user-friendly graphical representation of your process as you build it. You simply point-and-click to build flows, which run your business processes behind the scenes when something happens in Salesforce.

You next build a flow that updates the project as Complete when the shield status is changed to Fully Operational.

  1. Click setup icon and select Setup, then enter Flows in the Quick Find, and select Flows.
  2. Click New Flow.
  3. Make sure Start from Scratch is selected, and click Next.
  4. Select Record-Triggered Flow and click Create.
    Object selected and configured Trigger screen.
  5. In the Object field, select Space Station.
  6. Under Configure Trigger, select A record is created or updated. Combined with the Object field, this tells the flow to run whenever someone creates or updates a Space Station record.
    Completed flow entry conditions screen.
  7. Set Condition Requirements to All Conditions Are Met (AND). This field allows you to set criteria for the triggering record. The flow runs only if the criteria for that record are true.
  8. In the condition line, set Field to Shield_Status__c, set Operator to Equals, and set Value to Fully Operational.
  9. In the When to Run the Flow for Updated Records field, select Only when a record is updated to meet the condition requirements. This setting tells the flow to run only when the record change that triggered the flow included changing Shield Status to Fully Operational. If the Shield Status was already Fully Operational before the flow was triggered, the flow doesn’t run.
  10. Leave the other settings as their defaults.

Update Record Action

When the criteria evaluates to true (the Shield Status is changed to Fully Operational) you want the Project Status to change to Complete, indicating that the project is finished and your Space Station is ready for action! 

  1. On the flow canvas, on the path after the Start element, click Add Element. Select Update Triggering Record.
  2. Enter Update Status as the Label. Ensure API Name is Update_Status.
  3. Ensure Use the space station record that triggered the flow is selected.
  4. Ensure filter condition is set to None-Always Update Record.
  5. Set Field to Project_Status__c.
  6. Set Value to Complete.
    The Update Records panel corresponding to the preceding steps.
  7. Leave the other fields set to their defaults.

Post to Chatter

One last action before you put your flow into effect. When the project is complete and the shield is operational, you want to announce your amazing accomplishment in a Chatter post. This should make your boss happy.

  1. After the Update Status element, click Add Element. Select Action.
  2. In the Search Actions field, search and select Post to Chatter.
  3. In the Label field, enter Post to Chatter.
  4. Ensure the API Name is Post_to_Chatter.
  5. In the Message field, enter
    {!$Record.Name} is complete! Now witness the comfort of being protected by the best shield in the galaxy!
    The {!$Record.Name} text is special formatting that merges a field's value into the message text. The $Record value means “the record that triggered the flow”, and the {! and } characters mean "treat everything in these brackets as a field to merge into this field". So {!$Record.Name} is automatically replaced with the Name of the record that triggered the flow.
  6. In the Target Name or ID field, select Triggering Space_Station__c, then select Record ID.
    New Action screen completed.
  7. Click Save.
    • Flow Label: Fully Operational Space Station
    • Flow API Name: Fully_Operational_Space_Station
  8. Click Save.
  9. Click Activate to… uh… activate your flow.

Test Your Flow

Time to see your flow in action! To leave Flow Builder, click the back arrow in the upper left. Simply edit a Space Station record, set the Shield Status to Fully Operational, and click Save. When the page refreshes, the Project Status should display Complete and there should be a Chatter post in the page’s feed announcing how awesome you are.

Resources

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback