Business Logic and Process Automation

Business Logic and Process Automation Introduction

  • This is the largest area of focus for App Builder certification (27%)
    • Per MW, focusing heavily on this area gets you about halfway to a passing score (63%) on the App Builder certification exam
    • Per MW, process automation (with clicks instead of code) is one of the reasons why Salesforce has been so successful as a product

Goals

  • Determine which automation tool is appropriate for different scenarios:
    • Workflow Rules
    • Process Builder
    • Flows
    • Apex Code - don’t need to write actual code, just know when its appropriate
  • Time-base workflow queue
  • Approval Processes
  • Order of Execution in which Salesforce performs actions

Introducing Record Types

Helpful Practice Activity - Creating Account and Production Record Types

  • Example record types for Account
    • Client: Accounts that we have done business with. These usually have a won opportunity in their account history.
    • Prospect: This is a prospective client. We have yet to do business with this type of account. There will usually be an open or lost opportunity in the account history for these types of accounts.
  • Record types can be enabled/disabled by profile
    • When you first create a new record type, it is automatically set as default for the profiles using it
    • Page Layout Assignments: Different page layouts are assigned by record type, by profile

Helpful Practice Activity – Create Contact Record Types

  • Examples:
    • Customer: Someone external to our company that belongs to a client or prospect account.
    • Internal Employee: This is a contact record for one of our own internal employees.
    • Partner: This is a contact record type for someone that works for a partner company.

Helpful Practice Activity – Create Opportunity Record Types

  • In order to create a new Opportunity record type, the new record type must be associated with a sales process.
  • Example Sales Processes:
    • Product: Sales process for product sales.
    • Service: The Sales Process that we follow for opportunities with a Service.
  • Once the sales processes are defined, creating new record types on Opportunities is possible, and each new record type can be associated with one of those processes.

Assigning Default Record Types to Profiles

  • The default record type is selected by default during record creation for a given profile
    • Example: Custom: Marketing Profile by default creates new Accounts with record type Prospect
  • During the lead conversion process, these default record types and the profile of the running user will be used to determine the record types for the Account, Contact, and Opportunity that gets created

Record Type Sample Exam Question #5 from the Exam Guide

  • An organization needs to set the record type for a converted lead’s Account, Contact, and Opportunity based on the user who is converting the lead. How?
    • Set the default record types for each Profile for Account, Contact, and Opportunity to the desired record type for converted records.

Creating Picklist Fields and Record Type Implications

  • By record type, can specify different available picklist values and different default values
    • Set from an object manager page > Record Types

Creating Advanced Formula Fields

  • Invaluable resource from Salesforce on creating advanced formula fields. Examples below.
    • Available from “More Examples…” link on the formula editor in Salesforce
  • Account Rating
    • IF (AND (AnnualRevenue > 10000000,
      CONTAINS (CASE (BillingCountry, "United States", "US", "America", "US", "USA", "US", "NA"), "US")),
      IF(ISPICKVAL(Type, "Manufacturing Partner"), "Hot",
      IF(OR (ISPICKVAL (Type, "Channel Partner/Reseller"),
      ISPICKVAL(Type, "Installation Partner")), "Warm", "Cold")), "Cold")
  • Advanced Formula pane of New Custom Field includes more functionality than Simple Formula
    • Simple Formula is primarily for merge fields
  • Advanced Formulas + Validation Rules are the closest we will come to doing actual code in the App Builder certification
  • Google Search
    • HYPERLINK("http://www.google.com/#q="&Name,"Google")

Creating Cross Object Formula Fields

  • On Contact object, can create the following, which looks up to that Contact’s Account:
    • Account.Account_Rating__c

Formula Field Sample Exam Question #2 from the Exam Guide

  • There is no partial credit on certification exam questions. If the question states to choose two answers and you do not correctly select both, zero points are awarded.
  • A company’s app builder needs to display an account’s rating on all contacts related to that account. Which formula is valid in a text formula field on the contact to display the appropriate value?
    • CASE(Account.Rating, "Hot", "Hot", "Warm", "Warm", "Cold", "Cold", "Not Rated")
    • TEXT(Account.Rating)
    • Since the “rating” field on Account is a picklist, need to wrap it in a TEXT() or CASE() conversion

Creating Validation Rules

  • Validation rules are a means of preventing invalid from being entered into Salesforce as new records
    • These are set up within the object manager on a per-object basis
    • An example on Account:
      • AND(NOT(ISBLANK(AccountNumber)),LEN(AccountNumber)<>7)

Introducing Workflow Rules

  • Workflow automates the following types of actions based on your organization’s processes:
    • Tasks—Assign a new task to a user, role, or record owner.
    • Email Alerts—Send an email to one or more recipients you specify.
    • Field Updates—Update the value of a field on a record.
    • Outbound Messages—Send a secure, configurable API message (in XML format) to a designated listener.

Creating Workflow Rules

  • Workflow Rules are created via: Setup > Workflow Rules

Immediate Workflow Actions

  • Task, Email Alert, Field Update, Outbound Message
  • Workflow Rules cannot create new records (would need to use a Trigger or Process Builder)

Time Based Workflow Actions

  • Example:
    • Send an email: 1 - Day - After - Rule Trigger Date
  • Setting up Time-Dependent Workflow Actions is a two-step process:
    1. Add Time Trigger (Ex: 1 Day After Rule Trigger Date)
    2. Add Workflow Actions that fire on that Trigger Date (Ex: Send an Email)

Introducing the Time Based Workflow Queue

  • Locate via: Setup > Quick Find > “Time”
  • Actions that are set to take place in the future will appear here
  • If a change is made whereby the record no longer fits the criteria for the workflow, the task will be removed from the queue

Introducing the Lightning Process Builder

  • Locate via: Setup > Process Builder
  • Steps:
    1. Select your object - An opportunity, for example.
    2. Define your criteria - Let’s start this process when the opportunity’s stage is Closed - Won and its amount is greater than $500,000.
    3. Choose what to automate - Let’s create a contract and associate it with the opportunity’s account, congratulate the owner by posting to the Sales Chatter group, and create a follow-up task scheduled to execute six days after the opportunity’s close date.
    4. Activate the process

Creating a Basic Process in the Lightning Process Builder

  • During specification of process start time, can turn on recursion:
    • Recursion - Allow process to evaluate a record multiple times in a single save operation - up to six times if enabled
  • Cannot edit an Active process - it must be deactivated to make changes
  • As an example, we can post the Chatter when an Opportunity is changed to status “Closed Won”:
    • Congratulations to {![Opportunity].Owner.FirstName} {![Opportunity].Owner.LastName} for closing this opportunity.

Creating an Advanced Process in Lightning Process Builder

  • As an example, can specify to create a “Contract” record when an Opportunity with amount > $501,000 is changed to stage Closed Won.
    • On newly-created Contract record:
      • Account ID Field Reference = [Opportunity].Account.Id
      • Status = Draft
  • To turn on “Scheduled Actions” in Process Builder, need to check the checkbox: “Do you want to execute the actions only when specified changes are made to the record?” Leaving this unchecked means the process will fire even when irrelevant record updates are made.
    • Common situation is to create a Task record a specified number of days after Opportunity close date: On newly-created Task record:
      • Related To ID Field Reference = [Opportunity].Owner.Id
      • Priority Picklist = Low
      • Status Picklist = Not Started
  • Process Builder “Scheduled Actions” do not show up in the “Time-Based Workflow” queue.
  • Instead, check Setup > Process Automation > “Paused Flow Interviews”

Workflows vs. Flows vs. Process Builder – What to Use When

Ramifications of Field Updates and Potential for Recursion

  • Workflow Rules include a checkbox “Re-evaluate Workflow Rules after Field Change”
    • If this field update changes the field’s value, all workflow rules on the associated object are re-evaluated. Any workflow rules whose criteria are met as a result of the field update will be triggered.
  • Workflow Rules can get trapped in an infinite recursion loop if not thoughtfully set up:
    • Imagine a workflow rule that checks whether Account Rating = Warm, then sets Rating = Cold. Imagine another workflow rule that checks whether Rating = Cold, then sets Rating = Warm.
    • Uncheck the checkbox listed above to avoid this

Approval Processes

  • Set up Approval Processes via: Setup > Process Automation > Approval Processes
  • Users can “Recall Approval Requests” if they have submitted it
  • Approval Processes usually rely on email templates
  • Approval Processes are object-specific
  • “Entry Criteria” are specified for each Approval process
  • Special user hierarchical relationships can be set up for Approval Processes to follow
  • Can select to display a related list with “Approval History Information”
  • The allowed initial submitters can be restricted with a lot of granularity. Specific users, roles, etc.
  • The available initial submission actions are the same as those for Workflow actions (Task, Email Alert, Field Update, Outbound Message).
  • During the Approval Process, its possible to use Field Update actions to change the Record Type of the record going through Approval.
    • This makes it possible to change the page layout of the record as it goes through the process.
  • Best practice when setting up a new Approval process is to set one up with just a single allowed initial submitter and single approver, then work out the kinks. Approval Processes are a very deep subject.

Visualizing Approval Processes with the Process Visualizer

  • Click the “View Diagram” button to see a flow diagram view of the approval process
  • Open “Printable View” to see the actual numbered items and steps in the process, and how they associate to the diagram

Ownership Automation via Assignment Rules

  • Access assignment rules via: Setup > “Rules”
  • Primary Case Assignment rules are for Leads and Cases
    • Fundamentally, this is about assigning Leads and Cases to owners based on criteria
    • Owners can be Users or Queues
      • Setup Queues via Setup > Users > Queues
  • Each Rule consists of multiple ordered Rule Entries
    • If (Account: Billing CountryEQUALSUS,USA,United States,United States of America) AND (Account: SLAEQUALSGold,Platinum) AND (Account: TypeCONTAINSCustomer) then assign the case to the Service Queue, for example, might be rule entry #1

Ownership Re-Assignment and Alerts via Escalation Rules

  • Case Escalation rules are set up similarly to Assignment Rules and operate by a similar series of ordered Rule Entries
  • This is a time-based queue that automatically changes ownership of Cases after a certain amount of time has elapsed
  • Can view the Case Escalations queue through setup: Setup > Quick Find > Escalations > “Case Escalations”

Monitoring and Debugging in Salesforce

  • Debug Log is a helpful tool for Salesforce development. Access it via Setup > Quick Find > “Debug” > Debug Logs
  • Debug Log lets you set a User that you want to set a trace flag for, in order to monitor their activities
    • Any action they take on the platform generates debug logs
  • At time of taking these notes, Debug Levels can only be set in Classic, but they determine the level of granularity included in the Debug Log:
    • Categories: Database, Workflow, Validation, Callouts, Apex Code, Apex Profiling, Visualforce, System, Wave, Nba
    • Levels: None, Error, Warn, Info, Debug, Fine, Finer, Finest

Using the Developer Console

  • Access the Developer Console through Salesforce Classic. Click Name, then “Developer Console”
  • This is a browser-based development environment where you can create, test, and debug code
  • You need 75% Code Coverage in your Salesforce environment to deploy code
  • Can view debug logs from the Developer Console