Automate Across Multiple Salesforce Orgs with “Run Flow On Another Org” Action

This extension installs a new flow action called ‘Run Flow on Another Org’ that makes it easy to automate across orgs. The basic idea is:

  1. You have two different Salesforce orgs. Let’s call them Source Org and Target Org.
  2. You want to solve a problem involving the two orgs. For example, when a record gets created in Source Org, you want to create a copy in Target Org.
  3. On your Target Org, you create a flow that takes inputs and carries out work.
  4. You then create a flow on Source Org that incorporates the RunFlowOnAnotherOrg flow action. You can pass inputs in, including records and collections of records (although you’ll have to use the Serialize action to temporarily convert them to a string).
  5. When you run your Source Org flow and it reaches the RunFlowOnAnotherOrg, it will connect to your Target Org and run the specified flow there, passing in any inputs that you specify.

Setup

If you have two orgs that need this kind of integration, you probably already have them hooked up to some degree. But if not, you’ll need to create a Connected App on the Target Org that authorizes the Source Org to connect in. There’s detail on this here: Creating a Connection To Another Org That Your Flows Can Use

If you want to pass records or Apex-defined objects to the flow on the target org, you’ll need to first serialize them (turn them into a string). Then on your target flow you’ll want to deserialize them back to objects. This is easy with the Serialize/Deserialize extension, and well worth getting familiar with.

Install

This package currently requires that you first install the following packages:

  1. Flow Action Base Pack (version 3.0+)
  2. Flow Screen Components Base Pack (version 3.0+_
  3. Serialize/Deserialize

After installing the prerequisites, then install:

V 3.0 Unlocked 5/2/22

Source

source

Old Versions

1.0 Unlocked 10/11/21

From James Simone: Create Powerful Rollups in your Flows with a Single ‘Perform Rollup’ Action

Author: James Simone

A common question we see all the time when looking to roll data up is – “how do I easily roll up data when it’s not a Master-Detail relationship?” Previously, there wasn’t a good, free, flow-friendly and scalable method for doing so. The aspiring Flow acolyte might be tempted to think: “I could do this in flow!” After all, you’re just a few looping elements and assignment nodes away from having a rudimentary calculator figured out – and you did it yourself! Brilliant.

Then the requests start pouring in. Management loved that rollup you built so much that they’re asking for fifteen more fields to be rolled up to the parent-level too. They’d also like a dozen other metrics tallied in different objects. Now, you’re stuck with the unenviable task of trying to implement rollup features like concatenation, sums, counts, and more across a broad swath of objects. Suddenly, the prospect of wiring everything up in Flow seems a bit more daunting …

Introducing Apex Rollup

It doesn’t have to be so hard. Flow’s Apex Actions represent the next-level of customization when it comes to flexibility, speed, and ease of adoption, and this installable Apex Rollup extension takes care of all the necessary legwork when it comes to configuring rollup summary fields across any standard or custom Salesforce object with a lookup-based relationship – it even works with non lookup-based fields, as long as there’s a Text field that matches between objects!

Here’s a video introduction

Installation

Plus, because it’s an unmanaged package, it’s easy to install and upgrade to both sandboxes and production Salesforce orgs. Simply click the appropriate button on the Github Readme in order to get started:

Once you’ve installed the package, it’s on to our first exhibit! Let’s take a look at a common pain point in Sales Cloud – summing the Total Price field from Opportunity Products to their parent Opportunity’s Amount field.

Overview

This package installs 2 new Flow Actions called Perform Rollup and Perform Deferred Rollup that you can add to flows that, for example, trigger on changes to an Opportunity Product record. The action reads configuration information from a Custom Setting and one or more Custom Metadata Type Records and you can make changes to these records to add calculations to the flows that use this action without having to change those flows. 

How To Easily Sum Opportunity Product Prices To Opportunity Amount

Apex Rollup will make use of both a Custom Setting and a Custom Metadata Type to store configuration settings.

First things first – Apex Rollup ships with a Custom Setting, Rollup Settings, whose Default Organization Level values need to be enabled.

Configuring the Rollup Settings Custom Setting (One Time Step)

  1. In Setup, navigate to Custom Settings
  2. Click Manage next to “Rollup Settings”
  3. Click the Edit button above the “Default Organization Level Value” heading
  4. Check the “Is Enabled” flag

Creating Rollup Custom Metadata Type Records

Secondly, we need to configure our rollup’s objects and relationships. Apex Rollup stores this configuration information in a Custom Metadata Type (CMDT) called ‘Rollup’ that gets installed with the project. 

  1. Go to Setup –> Custom Metadata Types
  2. Click the Manage Records button next to the Rollup custom metadata type
  3. Click the New button
  4. Set up your custom metadata record so that the Parent Object values are correctly configured for Opportunity, and the Child Object values are correctly configured for Opportunity Product
    1. The Label field can be whatever you’d like. We tend to organize our rollup labels using the convention “Operation Child Object Child Field to Parent Object Parent Field” – which, for our example, comes out to “Sum OLI Price to Opp Amount” for the label
    2. The Parent Object should be Opportunity
    3. The Lookup Field On Lookup Object should be Opportunity Id
    4. The Rollup Field On Lookup Object should be Amount
    5. The Child Object’s Calc Item should be Opportunity Product
    6. The Lookup Field On Calc Item should be Opportunity Id
    7. The Rollup Field On Calc Item should be Total Price
    8. The Rollup Operation should be set to SUM
    9. The Rollup Control lookup record should be set to the Org_Defaults record that comes pre-installed with Rollup. More on this, later.
    10. Click Save – congrats, you’ve done it!

And here’s what the fully configured rollup CMDT record should look like:

Setting Up The Opportunity Product Record-Triggered Flow

Now that our settings are configured, we’re on to create a flow that makes use of our Rollup action.  We’ll walk through the creation of a new flow, but if you already have a RT flow set up for Opportunity Product, you should be able to follow along fairly easily, as we’re really just adding two elements to the flow.

Here’s what our final flow will look like:

  1. From Setup, navigate to Flows
  2. If you already have a Record-Triggered Flow for Opportunity Product, open that flow up
  3. Otherwise, click New and select Record-Triggered Flow
    1. The flow should be triggered when a record is created or updated
    2. It should run After Save
    3. Select Opportunity Product as the Object – there are no condition requirements
  4. Add a new Assignment Element to the flow. The purpose of this element is to collect individual records into a record collection variable that can be handed to the Perform Rollup Action.
    1. The label can be something like “Add records to collection variables”
  1. In Set Variable Values, click the Variable box and select “+ New Resource”
  2. Resource Type should be Variable
  3. API Name can be something like “CurrentRecords”
  1. Data Type is Record, and “Allow multiple values” checkbox should be checked off
  2. Check off the flag “Available for input” under the “Availability outside the Flow” header
  3. Save the resource, change the Operator field to “Add”, and use $Record (also represented as {!$Record}) as the value
  1. Repeat the above steps for another collection variable (can be called something like “PriorRecords”) and add {!$Record_Prior} to that second collection variable
  1. Add the Perform Rollup action to your flow and configure it:  
    1. click the plus sign on your Flow’s path, and select Action
    2. Scroll down on the left side till you see the “Rollups” category and click on it
    3. Select the “Perform Rollup__mdt-based Rollup” action
    4. Similar to step 4a in the “Creating Rollup Custom Metadata Type Records” section, Label can be whatever you’d like – but: we tend to organize our rollup labels using the convention “Operation Child Object Child Field to Parent Object Parent Field” – which, for our example, comes out to “Sum OLI Price to Opp Amount” for the label
  1. Object for “Prior records to rollup” (Input) and Object for “Records to rollup” (Input) should both be Opportunity Product, after which the additional fields will load
  2. Set “Rollup Context” to UPSERT
  3. Toggle the “Defer Processing?” field and add “{!$GlobalConstant.False}”
  4. Set “Prior Records to Rollup” to our “PriorRecords” collection variable
  5. Set “Records to Rollup” to our “CurrentRecords” collection variable that you created above.

The good news is that you’ve now successfully configured your first rollup!

Handling Record Deletions

 You’ll have to duplicate your work and create a flow that triggers on deletion of the records being rolled up(the only difference will be setting the “Rollup Context” field there to “DELETE”) in order to get everything up and running for all edge cases (Flow Orchestrator may help here!).

This is one of the only significant differences in setup for the Flow approach versus the Apex approach   because in Apex, a trigger can handle insert/update/delete all within one file., However, once your Flows have been setup, you don’t need to update them in order to add additional rollups, or to tweak your existing rollups; for that, all you need to do is modify your Custom Metadata Records. (If you add multiple rollups, it may make sense to relabel the first Rollup action to “Queue up Rollups for Opportunity Product” or something like that).

As you can see from the above screenshots, there are a significant number of optional arguments that you can use in Flow to further customize your rollups. Some of these serve as overrides for the individual Custom Metadata Records; the most commonly used option is the “SOQL Where Clause To Exclude Calc Items”, which allows you to only run rollups when records match the given where clause. For Rollups configured in the manner we’ve demonstrated above, it’s not recommended to use the “SOQL Where Clause To Exclude Calc Items” on the Action itself, but rather to configure those individually on the CMDT records. For more detail on the configuration options, look here.

Priming your Process With A One-Time ‘Backfill’ Rollup 

So, you’ve set up your rollups, as detailed above. There’s just one more step necessary. Apex Rollup calculates values for you in an ongoing fashion, which means that for all your pre-existing records, we need to backfill the correct values by performing a one-time calculation to assign the proper values to all parent records with configured rollups.

To do this, you’ll use the Rollup App that comes with this extension. This App isn’t normally going to be necessary because of the automation you’ve just created based on record creates and deletes, but it’s great for carrying out a one time manual recalculation.

  1. Click on the App Launcher
  2. Search for “Rollup”
    1. Click either “Rollup” under the Apps search result or
    2. Click the “Recalculate Rollup” item
  3. Both will bring you to the full recalculation Rollup application
  4. Because your rollup uses Custom Metadata Typess, toggle on the checkbox at the top of the page entitled “Run off of CMDT?”
  5. A combobox will appear where you can select individual rollup child types
  6. Once a child type is selected (like OpportunityLineItem), you can either choose to recalculate rollup values for each field one at a time, or, if you have multiple rollups per child object configured, all at once (by checking off all of the boxes)
  7. Click the “Start Rollup” button

And with that, we’re ready to roll … up! Once the calculation has finished, there’s no further maintenance required – as Opportunity Products are created / updated / deleted, their parent Opportunity’s Amount field will be kept in sync!

Further Reading

The Apex Rollup readme is filled with further information, and there is also a burgeoning Wiki being built out. Given that there are many, many possibilities for how to configure rollups, those two locations are the best place for finding more information about the configuration options available to you!

From Andy Schmiechen: An Introduction to Salesforce Orchestrator Webinar

Andy recently made this great presentation. It’s one of the first videos that uses the Winter ’22 Beta version, and it’s well worth watching.

Note that because Orchestrator is in Beta now, everyone can try it out. It will be a paid product, but all orgs will get a freemium allowance.

More on Salesforce Orchestrator

From Christine Talbot: When You Use ‘Navigate Everywhere’ To Navigate to a New Record Page, You Can Now Set Initial Values Using Flow Formulas (or static text, or upstream merge fields, or….)

This enhancement adds a defaultVals attribute to the action. As Christine explains:

When using DestinationType = ‘object’, and DestinationAction=’new’, passing a json string of ‘{FieldAPIName : value, FieldAPIName : value}’ will default those fields to the value.

Example:
To navigate to a new Contact page with defaulting the FirstName and the LastName fields via a formula field in the flow:

DestinationType = object
DestinationName = Contact
DestinationAction = new
defaultVals = {!formulafield}

{!formulafield} =
‘{“FirstName”: “‘ & {!firstname} & ‘”, “LastName”: ” ‘ & {!Last_Name} & ‘”}’

Install Here.

Official Orchestrator Help Is Now Online

The Beta version of Orchestrator hits this week. Here are the docs:

Other Orchestration information available here.

Mitch Spano – Orchestrate Your Flows and Apex with this Trigger Actions Framework

Mitch Spano over at Google has been hard at work over the years on his amazing Trigger Actions Framework, yet we’ve somehow never posted it on UnofficialSF. Mistakes were made, but I’m here to fix that!

If your team has been struggling with how to fit Apex Triggers and Flows together on the same object, this framework might be for you!

From the article:

Does your organization struggle to manage declarative vs programmatic automation within Salesforce? 🙋‍♂️

Do you have sObjects with a mix of Apex triggers, Flows, Process Builders and Workflow Rules? 🙋‍♂️

Do you want to have a better understanding of all the automation going on within your Salesforce org? 🙋‍♂️

The Trigger Actions Framework allows developers and administrators to launch Apex and Flows on a given sObject while maintaining complete control over the order of execution. 👇👇👇

Links:

A Big Official Blog Post from Salesforce on Process Builder and Workflow Rules

Salesforce has published extensive new guidance on what to expect regarding Process Builder and Workflow Rules:

Developer Corner: Bob Buzzard on Transaction Rollback in Flow

A nice new post from Bob Buzzard that explores transactional rollback:

The New Flow Bulkification and Transactions Wiki Page

The Flow Wiki has been built out to include a new page with links to good content about bulkification and transactions:

As is the case for all of the wiki pages, everyone is encouraged to propose edits by clicking on the Edit Article Button: