21
Advanced Flow Techniques with Apex and Visualforce Damien Phillippi Software Developer [email protected] [email protected]

Advanced Flow Techniques with Apex and Visualforce

Embed Size (px)

Citation preview

Page 1: Advanced Flow Techniques with Apex and Visualforce

Advanced Flow Techniques with Apex and Visualforce

 Damien Phillippi  Software Developer  [email protected][email protected]

Page 2: Advanced Flow Techniques with Apex and Visualforce

•  What are Visual Workflows and when should I use it?

•  How to combine with code.

•  Code Samples

Overview

Page 3: Advanced Flow Techniques with Apex and Visualforce

What is Visual Workflow? Software Developer, Soliant Consulting

Page 4: Advanced Flow Techniques with Apex and Visualforce

Visual Flows Triggered by User operation Visual and interactive Can effect or be effected by multiple objects Drag and drop interface Headless Flows can trigger events as well Restricted by governor limits

Workflows Triggered by events Behind the scenes Executes on specific objects Create Static processes

What Makes Visual Workflows different?

In short, you generally want to use Visual WorkFlows when you have a requirement similar to traditional workflows but it requires some sort of User interaction. For those not yet familiar with Visual Workflow:

https://developer.salesforce.com/trailhead/business_process_automation/flow

Page 5: Advanced Flow Techniques with Apex and Visualforce

•  Create a survey that can change frequently over time

•  Create a streamlined Case creation process for your org

•  Quickly create a set of related children for a record

•  Create a set of questions to follow along for a call center to give standardized scripts for the User

•  Replace some Apex Utility Triggers with Headless Flows

•  https://developer.salesforce.com/trailhead/business_process_automation/process_whichtool

Visual Workflow Use Cases

Page 6: Advanced Flow Techniques with Apex and Visualforce

Breakdown Point Flows tend to break down when you need to get more dynamic past the User interaction piece.

In my presentation, I will be showing you 2 such examples.

1)  You want to run a SOSL or dynamic query rather than a static query on an object.

2)  You might want to dynamically route your User or do different operations depending on earlier actions in your flow.

Page 7: Advanced Flow Techniques with Apex and Visualforce

Code with Visual Workflows Enhance your Flow with code

Page 8: Advanced Flow Techniques with Apex and Visualforce

Adding code helps strengthen Flows

•  Dynamic query filters

•  SOSL queries

•  Dynamic routing

Our First goal Create a way to search the database for matches in both Leads and Contacts.

Page 9: Advanced Flow Techniques with Apex and Visualforce

Create a global class with the @InvocableMethod in it

Page 10: Advanced Flow Techniques with Apex and Visualforce

Put a Simple Flow in a Visualforce Page that uses the Invocable class that was just created.

DF_Presentation.flow

DFPresentation.page

Page 11: Advanced Flow Techniques with Apex and Visualforce

Query Demo

Page 12: Advanced Flow Techniques with Apex and Visualforce

Add Error Handling What happens when more than a single record is returned?

DF_Presentation.flow updated

Page 13: Advanced Flow Techniques with Apex and Visualforce

Error Handling Demo

Page 14: Advanced Flow Techniques with Apex and Visualforce

Dynamic Record Routing Do we want to do something different if a Lead is found vs a Contact? Maybe we decide that any Leads coming through this route should immediately be converted and Contacts should be taken to their view page.

Page 15: Advanced Flow Techniques with Apex and Visualforce

This looks like it should work…

Unfortunately, this doesn’t work. The reason is that it fetches redirectUser as a property/variable. The method would need to be called getRedirectUser, but when it actually gets called it wouldn’t know about the flow variables yet by that point.

Page 16: Advanced Flow Techniques with Apex and Visualforce

Adjustments to the controller

Page 17: Advanced Flow Techniques with Apex and Visualforce

Updated VF page to work around the System

Page 18: Advanced Flow Techniques with Apex and Visualforce

Routing Demo

Page 19: Advanced Flow Techniques with Apex and Visualforce

Why not just use code?

•  Any changes to functionality require adjustments to unit tests and deployments through Sandboxes

•  Configurable by an Admin

Page 20: Advanced Flow Techniques with Apex and Visualforce

Closing In this 25 min, we showed you an example of some of the things you can do when you combine code/Visual Workflow.

•  Invoke code from Visual Workflows

•  Error handling.

•  Dynamic record routing

•  Alternate code with Flows: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_process_plugin_using.htm

•  Code can be found at: http://tinyurl.com/q92s6y9 •  Questions?

Page 21: Advanced Flow Techniques with Apex and Visualforce

Over the past ten years, our team has helped shape our clients’ futures as well as served to simply make their business lives easier. Our role extends well beyond being experts in creating custom software – we consider ourselves your trusted business partner.

IMPLEMENTATION As process consultants, we assist adoption by focusing on how your team works day-to-day.

APEX & VISUALFORCE Our versatile, experienced team has a deep understanding of Salesforce’s native languages.

APPEXCHANGE DEVELOPMENT We develop AppExchange solutions and navigate the Salesforce security review process.

SYSTEMS INTEGRATION Salesforce can seamlessly integrate with your existing business applications and IT infrastructure.