đź“Ł Attention Salesforce Certified Trailblazers! Link your Trailhead and Webassessor accounts and maintain your credentials by December 14th. Learn more.
close
trailhead

Add Business Logic

What You’ll Do

  • Create a Validation Rule
  • Create an automated process with Lightning Process Builder

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 Battle Station is not all sunshine, rainbows and lollipops. It's hard work that has to be done right. As you may have heard, we've had problems in the past with exhaust ports. There are too many of them and they are, apparently, very easy to shoot missiles into. This tends to make them blow up.

We want to prevent those pesky rebels from blowing up our Battle Stations again by fully staffing our 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. The boss can spot an open exhaust port from a parsec away!

You'll need to create a validation rule that prevents users from saving a record for a Exhaust Port Inspector if the utilization is less than 150%. Let's hope this keeps our Battle Stations from being blown to smithereens this time.

Add a Utilization Validation Rule

  1. Click Gear icon used to access Setup and select Setup. Select Object Manager tab next to the Home tab.

  2. Click Resource.

  3. Select the Validation Rules section from the left navigation.

  4. Click the New button.

  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 the Check Syntax button 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.

    Validation Rule Edit page is used to specify an error condition formula.

  10. Click the Save button.

Now go back to your Battle 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 the Lightning Process Builder

The Lightning Process Builder is a workflow 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 your processes which run "behind the scenes" in response to actions.

You'll build a process that updates the project as "Complete" when the weapons system is changed to "Fully Operational".

  1. Click Gear icon used to access Setup and select Setup. From Setup, enter Process Builder in the Quick Find, then select Process Builder.

  2. Click the New button.

  3. For Process Name, enter Fully Operational Battle Station. The API Name will populate automatically.

  4. From The process starts when, select A record changes.

  5. Click the Save button.

  6. Click the + Add Object icon to specify the object and when to start the process. It should kickoff whenever someone creates or updates a Battle Station record. For the Object select Battle Station and click the radio button next to when a record is created or edited.

    Process Builder is used to choose the Battle Station object and specify where to start the process.

  7. Click the Save button.

  8. Click the + Add Criteria icon to determine which criteria should evaluate to true to fire actions. You'll configure the process to run only if the Weapons Status value has been changed to Fully Operational.

  9. Enter Now Fully Operational for the Criteria Name and select Conditions are met.

  10. Click the Field picklist, select Weapons Status and click Choose. Change Operator to Is changed and Value to True.

  11. Add another criteria by clicking the Add Row button.

  12. Click the Field picklist, select Weapons Status (again) and click Choose. Change Operator to Equals and Value to Fully Operational.

    Process Builder is used to define criteria for the Now Fully Operational action group.

  13. Leave everything else as is, and click Save.

Update Record Action

When the criteria evaluates to true you want to change the Project Status to Complete, indicating that the project is finished and your Battle Station is ready for action! Blowing stuff up with large laser cannons is actually quite relaxing.

  1. Click the + Add Action button.

  2. For Action Type, select Update Records.

  3. Enter Update Status as the Action Name.

  4. For Record Type, click the search field and select the radio button for Select the Battle_Station__c record that started your process and click Choose.

  5. Set new field values for the record to update by clicking the Field picklist, select Project Status and change Value to Complete.

    Process Builder is used to select and define an Update Records action when the project status is complete.

  6. Click the Save button.

Post to Chatter

One last action before we put our process into effect. When the project is complete and the weapons are operational, we want to announce our amazing accomplishments by posting a message to Chatter. This should make your boss breathe much easier.

  1. Click the + Add Action button.

  2. For Action Type, select Post to Chatter.

  3. Enter Post to Chatter as the Action Name.

  4. For Post to, select This Record.

    Note: Please make sure you have enabled Feed tracking for the Battle Station custom object to view This Record.

  5. For the Message, enter {![Battle_Station__c].Name} is complete! Now witness the power of a fully armed and operational battle station!.

    The Select and Define Action page which is used to enter the Action Type, Name, Post To and Message when posting to Chatter.

  6. Click the Save button.

  7. Click the Activate button in the upper right corner to... uh... activate your process. Click Confirm.

Now that you are finished, the entire process should look like this.

Diagram showing what the Post to Chatter process will look like whem complete.

Test Your Process

Time to see your process in action! Simply edit a Battle Station record, set the Weapons Status to Fully Operational and click Save. When the page refreshes the Project Status should display Complete and there should be a Chatter post at the right of the page announcing how awesome you are.

The Battle Station detail record view highlighting the status fields and a red arrow poiting towards a Chatter post that appears on the right of the page

Resources

retargeting