RSS

Tag Archives: Flow DML Errors

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.


solutions-1

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

RecordUpdateOnly

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”

lets-go-down-to-funky-town


Using an Assignment Element

This is a very concise and quick way handle faults.

ErrorHandler

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

forgeahead

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

LkupLoopUpdate

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: , , , ,