Featured FlowDemo-10

Published on February 6th, 2015 | by Mike Gill

0

How To: Create Roll Up Summaries using Flow – Part 2

As promised and continuing on from my previous post on Creating Roll Up Summaries using Flow, I want to offer up one solution for recalculating Project Total Time on Delete of Time Entry records. Remember the last time? We showed how to use creations and edits of Time Entry records to calculate a rolled-up Total Time, but this didn’t take into account record being deleted. Here’s one way we can address that.

This part introduces us to some new flow features and techniques:

  1. Deleting a record
  2. Calling a Flow from a simple VisualForce page
  3. Calling an Existing Flow from within a Flow

Step 1 – New Flow

Start a new flow and drag a Screen element onto the canvas:

Screenshot 2015-02-06 12.04.15

This simple user Screen’s purpose is to warn the user they are about to delete the Time Entry record.

Here we simply add some text which is presented to the user when they hit the Delete Button. Nothing special here! (We tried removing this completely but had some issues as delete triggers a standard confirmation box, you will see when you build your own.)

Step 2 – Create Input Variables

Next we need to create a couple of Input Variables to take the following:

  1. Project record Id (Parent)
  2. Time Entry record Id (record to be deleted)

First we create the Project Id variable:

FlowDemo-Pic2

Input/Output Type should be set to Input only – this will be passed into the flow from the Visualforce page.

Last variable we need is one for Time Entry Id:

FlowDemo-Pic3

Same as with Project Id, Input/Output Type must be Input.

Step 3 – Delete the Time Entry record

Next we drag a Delete Record element onto the canvas.

FlowDemo-Pic5

This is easy to complete. In the Delete box enter the name of the Time Entry object and below that the Field we need is the Id field. Make this equal to Time Entry variable created previously.

Step 4 – Call our existing Flow which performs the Roll up summarisation

From within the Flow Designer, find and drag your previously created flow onto the canvas. (note: you need to complete the flow from our previous post and be in the same Org)

FlowDemo-Pic7

We have some simple config required here:

FlowDemo-8

In the Input/Output Variable Assignments section – Inputs tab

Set Target to varProjectId and Source to {!varProjectId}

In the Input/Output Variable Assignments section – Outputs Tab

FlowDemo-9

Here we basically do the same – easy!

Step 5 – Link the flow up

Now we just need to link our three elements together like this:

FlowDemo-10

Don’t forget to set the starting Element as the Delete Confirmation element.

Step 6 – Create our really easy Visualforce page

This is the closest we get to coding, but it’s not really as you can cut and paste our code…

Code for our Visualforce page:

<apex:page standardController="Time_Entry__c">

<flow:interview name="Project_Roll_Up_Part_2"

finishLocation="/{!Time_Entry__c.Project__c}">

<apex:param name="varProjectId" value="{!Time_Entry__c.Project__c}"/>

<apex:param name="varTimeEntryId" value="{!Time_Entry__c.Id}"/>

</flow:interview>

</apex:page>

You can create this page using the Developer Console or any IDE (ok, too technical).

Setup > Developer Console > File > New VisualForce Page

Give it a name and copy the code in from above and save it.

The important elements in the code are:

  • Interview name – This must be the exact API name of your flow
  • Param name – This must match the exact names of your Input variables (if not set to Input, it will not work!)
  • Finish Location – This is the clever bit, it returns the user cleanly to the Project record (you can check that everything got recalculated correctly)
  • Fields in the page follow the standard Merge format – hope it’s obvious enough to follow

Step 7 – Override the standard Delete button with this new Visualforce page

Navigate to: Setup > Create > Objects > Time Entry > Buttons, Links & Actions

Find the Delete button and override with your new Visualforce page:

FlowDemo-11

This will now open our new Flow on for deletes which handles now handles the actual Delete of the Time Entry record and then calls our first flow to reCalculate the Total Time.

And there you go, hope these two posts broaden your knowledge on what is capable with Flow with a little Process Builder and Visualforce to glue it all together. As always, comments very welcome.

Disclaimer Note: API deletions would not trigger a reCalculation

Tags: , , , ,


About the Author



Leave a Reply

Back to Top ↑