Given a scenario, identify common use cases and best practices for declarative versus programmatic customizations, including governor limits, formula fields, and roll-up summaries.

After studying this topic, you should be able to:

  • Identify the main features and use cases for declarative and programmatic customization.
  • Identify the declarative or programmatic solution for various simple and complex scenarios.
  • Describe the capabilities, functions, operators, and use cases for formula fields.
  • Describe the capabilities, types, and use cases of roll-up summary fields and the considerations when using them

Table of Contents

  • Customization Options
  • Declarative Customization
  • Programmatic Customization
  • Governor Limits
  • Simple & Complex Scenarios
  • Scenarios & Solutions
  • Formula Fields
  • Formula Field Scenarios
  • Roll-Up Summary Fields
  • Roll-Up Summary Field Creation
  • Roll-Up Count Type
  • Roll-Up Sum Type
  • Roll-Up Max Type
  • Roll-Up Min Type
  • Using Roll-Up Summary Fields
  • Roll-Up Summary Field Limitations
  • Roll-Up Summary Field Scenarios

Introduction - Declarative vs Programmatic Customizations

  • Declarative tools are become more advanced which minimizes the need to build complex solutions using programmatic tools
    • Which to use depends on declarative tool capabilities, the available programmatic options, and whether they are subject to governor limits
  • Formula fields and roll-up summary fields are custom field types that can be useful in almost all types of solutions implementation
  • Clicks vs Code: if a declarative tool can meet a requirement, it should be preferred

Customization Options

  • Three main options to customize Salesforce:
    • Declarative: simple, quick, automatically updated, point & click tools available in Setup
    • Installed: apps and components on AppExchange. Solutions have been reviewed and proven, and are already built.
    • Programmatic: use coding skills/tools, any feature or functionality can be implemented/integrated, maximum control and flexibility

  • Terminology notes:
    • Lightning Flow: product name for process automation tools
    • Flow Builder: used to create flows
    • Flow: automation application created using Flow Builder that may contain different types of actions to meet simple to complex requirements. May be invoked from the UI, record change, scheduled job, platform event, process, through Apex programmatically
    • Visual Workflow: retired product name for designing flows
    • Workflow: declarative automation tool used to create workflow rules using single if/then logic
    • Workflow Rule: used to define criteria that will trigger a workflow action
    • Workflow Action: action to perform when a workflow rule is met, such as field update, task, creation, sending outbound message or email alert

Declarative Customization

  • Declarative tools, in general, should be used to meet simple requirements
  • Use cases:
    • Display the sum or count of a number of related records: Roll-up summary field
    • Display the average of a number of related records: Roll-up summary field combined with a formula
    • Validate that a country code is a valid ISO code: validation rule
    • Ensure that a reson is entered before closing an opportunity: validation rule
    • Ensure that a number field has a valid format: regex function in a validation rule

Programmatic Customization

  • Programmatic = use of code
    • Solutions include Apex, Visualforce, Aura Components, Lightning Web Components
    • Programmatic customization is used to meet complex requirements or to:
      • Extend platform features, create a custom user experience, support complex business processes, add custom functionality, implement complex or custom transactional logic
  • Use cases:
    • Apex: create a custom web service, custom email service, complex validation
    • Visualforce: create a custom user interface, report with a custom format, define custom navigation patterns
    • Lightning Component: create a custom UI for Lightning Experience, extend Salesforce app with custom functionality, build apps with sophisticated UI using CSS, add client-side functionality, override standard actions in Lightning Experience, build a sophisticated UI for a lightning community

Governor Limits

  • Transactions that are invoked by a flow or process are subject to governor limits, just like Apex
    • SOQL queries issued: 100 queries
    • Records retrieved by SOQL queries: 50,000 records
    • Total DML statements issued: 150 statements
    • Total records processed from DML statements: 10,000 records
    • Maximum CPU time on the Salesforce servers: 10,000 ms
  • Additional considerations for Flows:
    • Maximum element executions per interview is 2000, Ex: Decision element and For Loop element
    • Using DML statements (like Update Records) inside a loop should be avoided
    • Creating complex formulas using formula variables affects Flow performance
  • Additional considerations for Processes:
    • One process per object consolidates actions and helps avoid hitting governor limits
    • More actions leads to higher DML statements or total CPU time - use single actions preferentially to multiple actions, if possible
    • Avoid infinite loops - for example, if a process creates a record, which triggers another process, which updates a record that triggers the initial process, you can hit governor limits

Simple & Complex Scenarios

  • Automatically create/update a record - Simple: Process Builder, Complex: Flow / Apex Trigger
  • Automatically delete a record - Simple: Process Builder, Complex: Flow / Apex Trigger
  • Process an email to a case - Simple: Configure Email-to-Case, Complex: Email handler in Apex
  • Create a custom report - Simple: Report Builder, Complex: Visualforce page, Custom Lightning Component
  • Schedule a job - Simple: Flow, Complex: Apex Scheduler
  • Share records - Simple: Sharing Rule, Manual Sharing, Teams, etc, Complex: Apex Managed Sharing
  • Validate a record: Simple: Validation Rule, Complex: Apex Trigger
  • Invoke an external web service - Simple: Outbound Message, Complex: REST or SOAP callout in Apex
  • Create a wizard that guides through a process - Simple: Flow, Complex: Flow, Apex/Visualforce
  • Conditionally display a form field - Simple: Flow, Complex: Visualforce Page, Custom Lightning Component
  • Perform a business process before a record is deleted: Simple: Flow, Complex: Apex Trigger

Scenarios & Solutions

  • More scenarios available in the FoF slides
  • Simple Scenario: user requires a report in tabular format with all closed opportunities - report builder
    • Complex Scenario: report with a custom format used by the business needs to be generated and rendered as a PDF file on a page - Visualforce code can generate the report and render as a PDF as well
  • Simple Scenario: reason should be entered when an opportunity is closed - validation rule
    • Complex Scenario: users should only be able to update an account if certain unrelated custom object records have been created - Apex trigger can be used for validation on complex logic
  • Simple Scenario: a community page needs to be customized to show a report chart - Lightning Component called “report chart”
    • Complex Scenario: a community page needs to display a highly interactive user interface that utilizes data from multiple Salesforce objects - custom Lightning Component can be developed and added
  • Simple Scenario: before an Opportunity record is deleted, a log record needs to be created to track the deletion for audit purposes - record-triggered flow that runs before opportunities are deleted, creates a log, and saves necessary info
    • Complex Scenario: record contains several URL fields, and the status code needs to be stored in dedicated fields after record is saved - Apex trigger can be created to perform asynchronous HTTP callouts to retrieve the status code of each link and save it to the fields

Formula Fields

  • Formula fields: read-only fields that automatically calculate a value based on other fields, expressions, or values
    • Automatically update using latest data, can merge fields on related objects, support a variety of return types:
      • Checkbox, Currency, Date, Date/Time, Number, Percent, Text, or Time
    • Simple Formula: selection of merge fields and operators
    • Advanced Formula: merge fields, operators, large range of functions to define the formula
  • Cross-object formulas can reference data from parent objects
  • Use Cases of Formula Fields
    • Concatenate values of fields and strings (using &)
    • Access parent fields (from child record)
    • Cross relationships (up to 10 relationships away)
    • Calculate dates (difference between dates, months from a date, etc)
    • Display images (ex: traffic light indicator based on other field values)
    • Conditional logic (IF statement) *** Match values** (determine a value from a set of values)
    • Display links (tracking URL based on tracking number)
    • Display currency (calculate commission amounts based on value of other fields)
    • Format text (remove formatting from another field, such as removing dashes from a phone number)
    • Display address (create a formatted address using spaces and line breaks)
    • Convert units (temperature conversion, miles->kilometers, etc)
    • Convert currency (local currency to corporate currency: CURRENCYRATE(CurrencyIsoCode))
    • Round numbers
    • Calculate dates (add a number of months to a specific date: ADDMONTHS(CustomerSignedDate,ContractTerm))
  • Formula field limitations:
    • Not possible to search a formula field
    • Dependency concerns: field values cannot depend on another field that references it
    • Unsupported fields include the long text area, encrypted, or description

Formula Field Scenarios

  • Phone formula field: Phone (Text): Contact__r.Phone
  • Email (Text): Contact__r.Email
  • Project Age in Days (Number): DATETIMEVALUE(Date_Completed__c)-DATETIMEVALUE(CreatedDate)
  • Reference to Project Stage (Text): IF(ISPICKVAL(Project_Stage__c, "Declined"), "Cancelled", IF(ISPICKVAL(Project_Stage__c, "Ongoing"), "Started", IF(ISPICKVAL(Project_Stage__c, "Completed"), "Delivered", "Pending" )))
  • Urgency Level (Number): Case(Client_Type__c), "Premium", 1, "Gold", 2, "Silver", 3, "Standard", 4, "Demo", 5, 5

Roll-Up Summary Fields

  • Availability: Can only be created on the master object in a master-detail relationship, or on some standard relationships, such as Opportunity-Product and Account-Opportunity
  • Limitations: Max of 25 roll-up fields per object, not available on certain types of formula fields
  • Functions: calculates Sum, Min, Max, Record Count of a field
  • 3-part definition of a roll-up summary field:
    • Summarized Object: child in a master-detail is summarized, custom objects on the master side cannot summarize standard objects on the detail side
    • Roll-Up Type: Sum: number, currency, percent Min or Max: number, currency, percent, date, date/time
    • Filter Criteria: by default, all records are included. Alternatively, a filter criteria can be specified.

Roll-Up Summary Field Creation

Reference FoF Slides

Roll-Up Count Type

Reference FoF Slides

Roll-Up Sum Type

Reference FoF Slides

Roll-Up Max Type

Reference FoF Slides

Roll-Up Min Type

Reference FoF Slides

Using Roll-Up Summary Fields

  • Ex: Consider a master-detail relationship between an object “Student” (detail) and a custom object “Class” (master). The institute would like to track the number of students with statuses (‘Interested’, ‘Verbally Committed’, and ‘Registered’) and the amount they paid for the class, ‘Revenue’
    • Solution: Roll-Up Summary Fields on “Class” object

Roll-Up Summary Field Limitations

  • Limitations:
    • Roll-Up Summary Fields can only be created on the master-side of a master-detail relationship
    • Maximum number on each object: 25
    • Limited support for standard relationships
    • Roll-Up summary fields are not available on custom lookup relationships
    • No cross-object support: field being rolled up cannot be a formula field that references a field on another object
    • Field being rolled up cannot be a formula field that contains dynamic date functions like NOW() and TODAY()
  • Overcome these limitations with:
    • Automation tools: Process Builder/Flow Builder
    • Apex Classes: Batch/scheduled Apex
    • Apex Trigger: Apex trigger on various DML events on the child object
    • AppExchange App: Third-party tools such as Roll-Up Helper

Roll-Up Summary Field Scenarios

  • Sales manager needs total number of all related property records to be displayed on the parent Account. He should be notified every time the total number increases.
    • ‘Count’ type roll-up summary field on Account plus an email alert in a Flow
  • Account record needs to display a summary of related Opportunities: total Amount, first Opportunity created date, latest Opportunity created date
    • Sum roll-up summary to aggregate Opportunity Amount
    • Min roll-up summary to aggregate Opportunity Created Date
    • Max roll-up summary to aggregate Opportunity Created Date
  • Sales manager needs to view minimum property amount in parent Project record. If it falls below \$5,000, project status must be updated to Pause-Property Needs Review value.
    • Min type roll-up summary to aggregate Property Amounts to get the least value, which is then used as criteria in a field update on a Flow