Author Archives: Karen

About Karen

Although I now live in California, and have been here for quite some time, I grew up in Alaska in a family where it was expected that everyone would be self-reliant and a self-starter. Along these lines I taught myself Excel VBA to the point where I'm pretty decent in that language, and I'm now learning about Salesforce Visual Flows, Process Builder, and Apex/Lightning (although the Apex/Lightning part is very, very much in it's infancy stage). This blog is a place where I write about discoveries I've made and notes I want to keep handy for future reference. Oh! And if you find yourself wondering about the chicken pictures, a few years ago my daughter told me we just had to get some silkie chickens. I had no idea what those were, but agreed to go along with the plan. Little did I know how delightful those crazy little beings would be and how quickly they would steal my heart. I now have several silkie chickens and love them all to pieces. They are astonishingly smart, cuddly, and delightful. I now cannot imagine life without them!

Sending Values To A Subflow

Sending Values To A Subflow

What Kind of Info Can be Sent Into and Received From a Subflow?

All kinds!

  • Primitive data types like text, number, Boolean, currency, date, date time, and picklist values
  • Collections of primitive data types
  • sObject collections

So What’s So Interesting About That?

Here’s what’s interesting:

Subflows, when receiving information from or or sending information to a calling flow, must have access modifiers on those variables to expose to the calling source (Other Flows, Visualforce, and Apex).

Calling Flows, however, do not need access modifiers on variables used to send information to or receive information from a Subflow. In other words, calling Flows can keep all of their variables Private.

What’s An Access Modifier?

Access Modifiers

Access modifiers define where the item can be viewed and used. For Flow variables the access modifiers are:

  • Private
    • The variable can be used only within the Flow
  • Input only
    • The value of the variable can be input into the Flow
  • Output only
    • The value of the variable can be received by a calling Flow
  • Input and Output
    • The value of the variable can be input into the Flow and is also available for a calling Flow to receive back

Private sign

[As an aside, Apex access modifiers are slightly different: Private, Public, Global]

What Does This Mean?

  • Items without access modifiers (Constants, Text Templates, and Formulas) can be used to pass values to a Subflow
  • Variables without access modifiers can be used to receive values from a Subflow
  • Only variables that need to be exposed to an external source need to have an access modifier other than Private

Using Constants, Text Templates, and Formulas

Using items that do not have access modifiers to set values for a Subflow sort of makes sense because when you call a Subflow you can simply type a value into the Source field, which would sort of be the same as using a Constant.

Subflow typed input

Typing a value into the Source field


Subflow Input Using Variable

Using a Constant, Text Template, or Formula in the Source field

Keeping Subflows Easy To Use

Make it Easy

When working with a single Subflow things are pretty straightforward: The Input and Output variables you see in the Target picklists will pertain to that Subflow only.

However, when a Subflow in turns uses other Subflows, the visible variables can start to get a little confusing. Variables that have been marked as Input because they are receiving information from another Subflow are now exposed to the original calling Flow. They don’t really need to be initialized by the calling Flow, yet there they are in the picklist when you click on the Target field.

Here is an example of a Subflow that has several Target variables:

Lots of Input Options

If some of these variables can be marked Private the Target selection becomes much easier:

Simplified Input List

Simplified Target Variable Selection

There you have it. Simplification. It’s a beautiful thing.

Leave a comment

Posted by on October 18, 2017 in Flow Tips & Tricks, Visual Flow



Visual Flow Error Handling Utility Flows

Visual Flow Error Handling Utility Flows

When I start a new project I often want to skip over the preparation stage and dive right into the deep end. For me that’s where the fun is! Along those same lines I have been known to drag my feet with finishing a project, but that’s a story for another time.

So ignoring setting up all the stuff needed to handle errors and immediately dig into the heart of the project often applies to me when I’m writing a new Flow.

And that’s exactly what happened again yesterday. So I asked myself, “Self, how can you make this easier?” (or something like that)

Here is what I came up with: two utility flows

  • One to retrieve the bits and pieces needed for error reporting (and some other stuff)
  • One to do the error reporting.

Happiness is a good report card

Two Utility Flows to Handle All Errors

  • Error Handler Items
  • Error Handler

Two Utility Flows to Handle Errors

The Error Handler Items Flow

Error Handler Items Flow


Error Handler Items Variables

This flow does two things:

  1. Fetches and returns an email collection of Users who have been designated to receive error messages
    1. Retrieving Stick on Bridge
    2. I’ve added a custom Boolean field to the User object, “Is Flow Error Recipient,” and have set it to True for Users who should receive error messages
    3. If there are no Users with this field set to True, the Users assigned to the System Administrator profile will receive the error messages
    4. This collection is necessary in the Error Handler Flow if that Flow is to send an email
  2. Returns the name of the User who launched the Flow
    1. Get User Name Formula
    2. This information is not required in the Error Handler Flow, but is made available for the calling Flow to use

Of course if you wanted to make other items available to your calling Flow you could certainly do so. This could be a handy-dandy utility flow for fetching all sorts of things that you may need on a regular basis.

The Error Handler Flow

Error Handler Flow


Error Handler Variables

This flow does also does two things:

  1. It constructs an email Subject and Body (that’s what the Text Templates do)
  2. It sends an email to the addresses in the

Parts of an email

What is Gained?

At first blush this solution looks pretty much like the same amount of work as my prior solution where I used a utility flow to fetch the collection of email addresses and a Send Email element to report the error.

Old Error Handling Method

And certainly the number of elements I’m dragging into the Cloud Flow Designer is the same.

Where it saves time and attention is in these areas:

  • The email Subject and Body are generated by the Error Handler flow so I don’t have to create formulas or text elements in each flow to do this
  • If I want to change how the generated email looks I have only one place I need to go (as opposed to every single Flow where I have a Send Email element)
    • This is huge for me as I’m all over the page here – having a single place where these items are structured will make for more consistent error reporting
  • If I want to display the User’s name in the Flow, Error Handler Items exposes that information so I don’t have to create a function to get it
    • If I want the way a User’s name displays to change I have only one Flow to update to make that happen across all Flows
  • If I want to use other items on a regular basis I can use the Error Handler Items Flow to expose them

Save Time Fuzzy Ball

As my knowledge of Visual Flow has expanded I have revamped my error handling a couple times and I can honestly say that just the second bullet point alone is well worth the trouble of revamping it again. So that is my task for today: revisit all the Flows where errors need to be handled and install this method. For me it’s a small price to pay to be able to quickly update my error reporting down the road.

Time to Revamp


Leave a comment

Posted by on October 18, 2017 in Flow Tips & Tricks, Visual Flow



Calling Subflow’s That Do Not Need Input

Calling Subflow’s That Do Not Need Input

Did you know that you can create Subflows that doen’t require input? It seems so logical that this could happen I’m stunned that I didn’t figure this out a couple years ago!


There is just one simple trick to making this happen: when you call the Subflow, delete the row that is looking for input.

Here is what a call to a Subflow looks like:

Call to subflow

See the little trash can to the right of the Target and Source input fields?

Trash can icon

Click on it and the row disappears.

Subflow after row is deleted

So simple and so useful!

Leave a comment

Posted by on October 17, 2017 in Flow Tips & Tricks, Visual Flow


Tags: ,

Get Nth Element of Collection Flow

Get Nth Element of Collection Flow

A few days ago I read in Dan Appleman’s book, Advanced Apex Programming, that “all of your Apex code should be designed to handle bulk operations. All of it – no exceptions” which shot me off on a tangent yesterday to see if I could “bulkify” my Get RecordType Id Flow (Lookup RecordType Ids in Visual Flow – A “Bulkified” Approach). My solution ended up being a combination of three Flows, with the third one returning the Id at a specified index from a collection of Ids.

As I was putting the finishing touches on that project it dawned on me that the third flow could be a generic utility Flow that simply returns the nth element of any input collection. Instead of having a Flow that only works on Id (Text) collections (and is named in such a way that I may not think to use it in other situations), why not have one that will work on all sorts of collections?

tele tubby sunrise

Overview of the Flow

The Get Nth Element of Collection Flow

So far this Flow handles two types of collections: Text collections (elements are outlined in green) and Number collections. I really only need it to handle Text collections right now, but for the exercise of figuring out how to make it work I included handling Number collections.

More Specifics

Handling One Collection


In order for this Flow to handle different types of collections (Text, Number, SObject, etc) it must have input collection variables for each type. Since mine, so far, handles only two types of collections I have two input collection variables. You could add all sorts of collections to your Flow including collections of  SObjects, like Accounts and Contacts.

Input collection variables

Other than counters the Flow also will need an input variable to receive the requested index, output variables for each collection type and variables to use in your Loop elements.

Other variables

The Flow of the Flow

The first thing it does is count the number of elements in one of the input collections. The collection that the Flow starts with is arbitrary – mine just happens to start with the Text collection.

Get element count

If the Flow determines that there are no elements present it proceeds to the next collection.

If elements are present, there is a quick check to make sure that the requested index is within the number of elements in the collection.

Check for Valid Index

Valid Index Check

If the requested index is invalid the Flow assigns a message to an output variable that the calling Flow can choose to receive and check.

If valid, another loop parses through the collection and saves the nth element to a result variable.

Finding the Nth Element

Using the Flow

Here is an example of how you would use the Flow to retrieve the 2nd element of a text collection:

Asking for the 2nd element of a collection

And how you would get your result back:

Receiving the result

Optionally you can also ask for the number of elements in the input collection, and an error message:

Getting optional items

Some Additional Details

Element Count

For my purposes I’ve exposed the count of the number of elements in the collection to the calling Flow (ElementCount is an output variable). This is totally optional. I have another utility Flow that counts the number of elements in a collection that I could use but if there was ever a need to know the number of elements and retrieve a specific element this Flow would do both in one fell swoop.

Two birds with one stone

Alternate Ending

And here is an alternate way to handle the end of the flow for any given collection:

Alternate Ending

In this ending, as soon as the result is located the Flow exits. Unless you’re working with extremely large collections this ending probably won’t save any time, but for what it’s worth, it does increase the efficiency of the Flow some infinitesimal amount.

A word of caution about exiting a loop prior to parsing the entire loop. If you do this for a loop within a loop you’ll get some really inaccurate results. This is because Salesforce doesn’t begin looping through a collection at the beginning of it if you’ve previously exited it somewhere in the middle. This was a situation I discovered very early on in my Flow experience which gave my simple mind much grief at the time (Flow Loop Doesn’t Start at First Record)!



Posted by on October 12, 2017 in Flow Tips & Tricks, Visual Flow


Tags: , ,

Lookup RecordType Ids in Visual Flow – A “Bulkified” Approach

Lookup RecordType Ids in Visual Flow – A “Bulkified” Approach

I find myself feeling so excited when I learn new tricks that can elevate my prior and current work, and this is a new approach to retrieving RecordType Id’s in a “bulkified” manner (as opposed to a single record approach in my prior post Lookup RecordTypeId Subflow) that has done just that.

What is Bulkification?

Bulkification is the process of structuring code to handle the processing of multiple records (as opposed to a single record) for better code efficiency. On the Salesforce platform this is critical as it is a multi-tenant platform with shared resources. Dan Appleman, author of Advanced Apex Programming, has gone as far as to say “All of your Apex code should be designed to handle bulk operations. All of it–no exceptions.”

no exceptions.jpg

After reading that I began to think…hmmmm…I wonder where I can change some of my Flows to “bulkify” them to a greater extent. His quote does specify “Apex,” but what about Flows? In that light I set out to see what could be done, starting with my Get RecordType Id flow.

Now, as you’ll see below, the bulkified process is much more complex than simply calling a single record lookup Flow two or three times. And to be sure, there is a trade-off: Multiple DML statements versus multiple looping. So after completing this project I decided it would be prudent to keep the original flow in my tool box for those instances where I need a single RecordType Id, even though it isn’t “bulkified.” 🙂

Overview of “Bulkified” Get RecordType Ids Flow

The Bulkified Flow

How it Works

  • The Flow receives two collections
    • One collection has object names
    • One collection has developer names
    • Input collection variables
    • The names at each index in these collections must correspond – in other words, if the first object name is “Account” then the first developer name must be a developer name for an Account RecordType
  • It then looks up all active record types saving the following fields into a collection (you could include inactive record types as well, if you wanted to)
    • Id
    • DeveloperName
    • SObjectType
  • Now, transferring the requested RecordType Ids requires three loops: an outer loop and two inner loops within that outer loop
    • The first two loops (the outer loop and first inner loop) get a Developer Name – Object Name pair
  • The Outer Loop
    • The outer loop parses over the developer names collection
      • Loop thru developer names collection
      • Within this loop a count variable (count1) is incremented and another count variable (count2) is set to zero
      • Increment count1
      • (It was just arbitrary that I looped over this collection first and the object names collection second – you could choose to do it in the opposite order if you’re so inclined)
  • The Second Loop (First Inner Loop)
    • The second loop parses through the object names collection
      • Loop thru object names collection
      • Within this loop the count2 variable is incremented
        • When count2 is equal to count1 the object name is stored
      • At the end of the loop, control passes to the third loop
  • The Third Loop (Second Inner Loop)
    • The third loop parses through the record type ids collection
      • Loop thru record type ids collection
      • When the developer name matches the developer name of the first loop’s variable and the object name stored from the second loop the Id for that record is saved in a collection
      • Add RecordType Id to a collection
      • At the end of the loop, control passes back to the first loop where the next element in the developer names collection is then processed
  • The final output is a collection of RecordType Ids

Word of Caution

Be sure your inner loops always parse through the entire collection. Exiting a collection early in an inner loop can give you erratic results. Who needs that?! (See Flow Loop Doesn’t Start at First Record)

How to Call The Get RecordType Ids Flow

Since this Flow requires input of two collections I decided to create another Flow that constructs those collections and launches the one outlined above (I call it the Get RecordType Ids Launcher).

Get RecordType Ids launcher

This Flow does the following:

  • It receives the developer names and object names in separate input variables
    • wrapper variables
    • (Additional DeveloperName# and ObjectName# variables can be created if more than three RecordType Ids are needed)
  • Then it adds the names to collection variables
    • Adding names to collections
  • After the collections are built it launches the Get RecordType Ids Flow and receives back a RecordType Ids collection
  • Finally it returns the RecordType Ids collection to the calling routine

Getting a RecordType Id for a Specific Index

So how do you get an Id at a specific index within a collection? In order to do that I wrote a third Flow (I call it my Get RecordType Id by Index Flow).

Get recordtype ids by index

  • This Flow receives a collection of RecordType Ids and an Index number
  • It starts by doing a quick check to make sure the Index is within the number of elements of the RecordType Ids collection
    • Index error check
  • Then it loops through the Id collection
    • Loop thru Id collection
    • For each element a count variable is incremented
    • If the count is equal to the Index the RecordType Id is stored
  • Finally it returns the stored RecordType Id

Putting it All Together

Putting it all together

When this solution is put to work the following happens:

  • A call to the Get RecordType Ids Launcher Flow retrieves a collection of RecordType Ids for the object name – developer name pairs entered into that Flow
    • Calling the Get RecordType Ids Launcher Flow:Call to Get RecordType Ids Launcher
    • Getting a collection of RecordType Ids back:

      Getting RecordType Ids collection

      Getting a Collection of RecordType Ids Back

  • Now, for each RecordType Id that is needed, use the Get RecordType Id by Index Flow to retrieve the Id
    • Calling the Get RecordType Id by Index Flow:Calling the Get RecordType Id by Index Flow
    • Getting the RecordType Id backGet RecordType Id back


A Couple More Thoughts

  1. By all intents and purposes you could choose to combine the “launcher” Flow with the Get RecordType Ids Flow. I chose to break these processes apart to keep increase the number of options I have for retrieving RecordType Ids.
  2. The Flow for returning a specific RecordType Id by index could be (and probably should be) a generic Flow that receives a collection variable (containing any sort of information) and returns the value from the collection that corresponds to the specified index. After this occurred to me I wrote a more generic version of it: Get Nth Element of Collection Flow.

So there you have it. In my box of Flow tools I now have a Flow that will lookup a single RecordType Id, and a set of three Flows that I can use when I need multiple RecordType Ids but I need to conserve DML calls.


heavy weight

Leave a comment

Posted by on October 12, 2017 in Flow Tips & Tricks, Visual Flow


Tags: , ,

Flow DML Error with RecordDelete and RecordUpdate

Flow DML Error with RecordDelete and RecordUpdate

Here is a quickie on handling Flow DML errors for RecordDelete and RecordUpdate when there are no records in the database that match the lookup criteria.


The RecordDelete and RecordUpdate elements will throw an error if no records are found:

So if there is any chance the database will not be able to find a record to delete or update you need to account for this.

There are two possible solutions:

  • Handle the DML fault
  • Do a FastLookup and check for the presence of records prior to performing the RecordDelete or RecordUpdate

Handling the DML Fault


Here are three methods I use to handle faults:

  • Use a Send Email element to notify Users who should receive error messages (uh…that would be me!) that there has been a problem
    • This is a very common way of handling flow faults
  • Use an Assignment element to add a value to a variable that is passed back to a calling Flow
    • This one works great in situations where you want control over how and where the fault is handled (like when one Flow calls another and you want the calling Flow to handle the error)
  • Just skip on to the next element in the Flow
    • In other words, point both the regular arrow and the Fault arrow to the next element in the Flow and just ignoring that an error has occurred
    • Sticking_tongue_out

Using a Send Email Element

I have a utility Flow that looks up and returns collection of User email addresses for Users that have a custom variable that I’ve named “Flow Error Recipient” set to True. I then use that collection to email all the Users who should be notified that an error has occurred.

Send email element

  • The body of the email address is essentially the Flow Fault message dolled up with the Flow name and what-not:
    • ErrorMsg
    • In this particular example I’ve used a Formula to create a dull, dry error message, but a Text element could also be used and you could go to town making it all pretty and adding all sorts of information, like the Flow name, version, and whatever else your heart desires
  • The Subject has the name of the Element that went awry, in this case “UpdateClientAcct”


Using an Assignment Element

This is a very concise and quick way handle faults.


Essentially you’re just doing nothing, or maybe you’re initializing an output variable with a value that a calling Flow can evaluate. In the example above I’ve pointed the fault toward an Assignment element that assigns a variable to itself (essentially doing nothing).

Assign a variable to itself

Forging on Ahead Method


If you needed your Flow to do other things after the RecordUpdate or RecordDelete element you would point both the regular arrow and the fault arrow toward whatever comes next in the Flow. Pft.

Flow fault handling

Caveat for This Method!

  • If you have any AfterUpdate or AfterDelete triggers this method may throw an error if those triggers do not watch for a null trigger collection:
    • Error Occurred: The flow tried to delete these records: null. This error occurred: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: dlrs_HhEnrollTrigger: execution of AfterDelete caused by: System.DmlException: Update failed.
  • Workaround? Use the Fast Lookup Method shown next

Method Using Fast Lookup


This solution takes a little more work, but perhaps is a more “correct” approach than just forging on ahead?  😉

  1. Lookup the records to be updated or deleted and put them in a collection variable
  2. Check to see if the collection variable is null
    1. If null, either exit the Flow or continue with the next thing that the Flow needs to do
  3. If updating the record, do one of the following:
    1. Loop through the collection variable making updates and adding the updated records to a new collection variable, then update the new collection using a FastUpdate
    2. Use a RecordUpdate
  4. Or, if deleting the records, do a FastDelete on the collection

Ta da!

no more error messages

Leave a comment

Posted by on October 6, 2017 in Flow Tips & Tricks


Tags: , , , ,



What is LockerService?

Following the advent of Lightning Components came the introduction of a security feature for those components called LockerService.

LockerService is a suite of technologies for providing security to Lightning components including (but not limited to):

  • Enforcing JavaScript ES5 Strict Mode
    • This keeps JavaScript interacting with components int he same namespace
  • Containing DOM access to the same namespace
    • This keeps components from different namespaces from interacting with each other
  • Providing wrappers for non-secure global references
    • Objects that are considered “non-intrinsic,” such as window, are considered to be secure
    • LockerService provides a secure version of these objects for Lightning components to interact with (example secureWindow) where access to the object is filtered
    • The secure wrapper can be used in the same way as the non-intrinsic object
  • Restricting JavaScript methods to supported JavaScript API methods only
    • You can find the methods that are supported by going to:
      • https://<myDomain>
      • where <myDomain> is the name of your custom Salesforce domain
  • Enforcing stricter Content Security Policies (CSP)
    • This prevents cross-site scripting, clickjacking, and other code injection
Gum wrapper dress

Gum Wrapper Dress!

LockerService became a critical update in the Summer ’16 release.



Leave a comment

Posted by on October 3, 2017 in Security