Chapter 4. Implementing Business Logic

We studied the basics of App Development on Force.com. We created database objects, page layouts, and tabs. Now that we have created our model and view, it is time to add some business logic. Business logic is the brain of the application; it makes sense of the data and responds to the button clicks in the UI.

A controller in the Model-View-Controller architecture forms the bridge between a Model (Data) and View (Display). We can write the business logic in the Apex code as well as in a declarative syntax. In this chapter, we will focus on the declarative syntax to write business logic.

In this chapter, we will cover the following topics:

  • Choosing between different automation tools
  • Automating the business process using workflows
  • Setting up a workflow rule that fires after a particular time
  • Routing records using an approval process
  • Automating using the Lightning Process Builder
  • Creating wizards with Visual workflows

Automating business processes

There are different ways to automate repetitive business processes on the platform. We can use any of the following tools to do this:

  • The Lightning Process Builder
  • The Visual workflow
  • Workflows
  • Approvals

The automation tool that we need depends on the type of business process that we are automating.

For example:

  • If a user does not return the book in seven days, the librarian sends an e-mail reminder to him to return the book
  • If a user updates his address in the system, an automated update should happen in an external inventory management system or an address book
  • If a user misses out on a payment of a fine or returns a book after the due date, the user is marked as black-listed
  • Managers approve the discount requests for the amount of the fine
  • Customer Support uses a wizard to capture new cases and so on

Doing something when a record has values

  • The most common repetitive business process is to perform actions based on the value of the record. This type of process automation can be created in workflows, the Process Builder, and visual workflows.
  • If the process boils down to a single if/then statement, it is recommended that you use the Process Flow.
  • If there is a time-dependent action (a delayed trigger) or the action is an outbound message, we should use workflows.
  • If the process is far too complex with multiple if/then statements and follow-up if/then statements, we must use visual workflows.

Getting information from customers

One of the biggest drawbacks for all the process automation tools on Salesforce has been the inability to perform actions on the data, while it was being entered. This limitation is solved using Visual Workflow.

For example, creating an Opportunity capture wizard that lets the customer representative fill out a form to create opportunities.

Getting a record approved

If the process requires an approval from a manager in the hierarchy, we can use an approval process.

Features

The following table explains the features used in the various tools:

 

Workflow

Process Builder

Visual Workflow

Approvals

Single if/then Statement

YES

YES

YES

YES

Complex if/then- if/then statements

No

No

YES

No

Drag and Drop designer

No

Yes

Yes

No

Is triggered when

The record is changed

The record is changed

A user clicks on a button or link

A user accesses the custom tab

The process starts

The Apex method triggers

A user clicks on a button or link

A process or flow calls the Submit for Approval action

The Apex method triggers

Supports time-based actions

Yes

Yes

Yes

No

Supports user interaction

No

No

Yes

Yes (Only for approvals)

Call Apex methods

No

Yes

Yes

No

Create and Delete Object records

Only Tasks

Only Create

Create and Delete

No

Post to Chatter

Yes (Pilot)

Yes

Yes

 

Send email

E-mail alerts

E-mail alerts

Yes

E-mail alerts

Send outbound messages without code

Yes

No

No

No

Submit for approval

No

Yes

Yes

No

Update fields

The record or its parent

Any related record

Any record

The record or its parent

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.12.160.66