Add Business Logic | Trailhead Screen Reader Instructions

Add Business Logic

So now we have our basic app in place, and users can maintain data and manage the project. However, we have some business rules for these type of projects that we'd like to put into place.

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 be fully staffed on each project and even put in overtime hours.

You'll 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. Activate the Setup button near the top of the page and select Setup.
  2. Select the  Object Manager tab, or search it from the search field at the top of the page.
  3. In the table listing all objects in your org, press ENTER on the link for  Resource.
  4. Under the Resource heading, select the Validation Rules tab.
  5. Activate the New Validation Rule button.
  6. For the Rule Name enter: Inspectors_Must_Work_Overtime
  7. 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%.
    Locate the edit field just above the Check Syntax button. This is the formula editor, and it's where we will be entering the text for our formula. Enter the formula just like this:
    AND(Name = "Exhaust Port Inspector", Utilization__c < 1.5)
  8. Click the Check Syntax button to make sure the formula has the correct syntax.
  9. For the Error Message, enter: Exhaust Port Inspectors must work at least 150%. No coffee breaks!
  10. For the Error Location, select the  radio button  for field, and then select the Utilization field from the combo box below it.
  11. Activate the Save button.

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 system is changed to Fully Operational.

  1. Click the Setup button and select Setup. Enter Flows in the Setup search field, then select Flows Process Automation.
  2. Click the New Flow button.
  3. Select Record-Triggered Flow and click the Create button.
  4. Below the Configure Start heading, in the Object field, select Space Station.
  5. 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.
  6. 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.
  7. In the condition section, set Field to Shield_Status__c, set Operator to Equals, and set Value to Fully Operational.
  8. In the grouping for When to Run the Flow for Updated Records, select the radio button option for 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.
  9. Leave the other settings as their defaults, and click the Done button.

 

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 Builder canvas, click the Add Element button, and select Update Triggering Record from the menu.
  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.
  7. Leave the other fields set to their defaults, and click the Done button.

 

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 the Add element button. Select Action from the menu.
  2. In the Action field, 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!
  6. In the Target Name or ID field, type $Record, and select the result that says SObject $record Space Station. In the list that appears after pressing ENTER on that, type ID, and select the result that says String ID Space Station Id.
    The field’s text should now be {!$Record.Id}. You can enter this value into the field directly if necessary. The $Record value means “the record that triggered the flow”. So {!$Record.Name} is automatically replaced with the Name of the record that triggered the flow, and {!$Record.Id} is automatically replaced with the ID of the record that triggered the flow.
  7. Leave the other fields blank, and click the Done button.
  8. Click Save.

 

Test Your Flow

Time to see your flow in action! TO leave Flow Builder, click the Back link at the top. 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

Click to return to the unit on Trailhead to verify this step.