0

I've created a flow on an error log record creation (it's a custom object) and since it's a batch job that generates these records, want to send an email alert to the admin to inform them of the error.

The flow works nicely if I keep it simple, ie on create of a new record send the email with the record details. However, our batch job runs every 5 min and if the same error condition still exists it will create a new record (and thereby new email) every 5 min.

In the flow I would like to determine whether there is already a record with those same details (ie the error is the same one for the same record) to avoid sending multiple emails every 5 min. I thought it would be simple to query existing records where the 3 values I compare are identical, and if so, to not send another email. It appears though that the flow runs AFTER the create/commit of the new record, and the query actually picks up the newly created record, and therefore my check for a null result (ie no duplicate entry found) will never be met.

I can't seem to tell it to ignore the new record or check before it actually commits the save. So is my only option here to do this in a trigger, since the flow doesn't seem to allow me to do this check? Or is there something I'm missing in flows?

1 Answer 1

2

Instead of checking for a null result, check for number of records == 1. Use the Assignment element in Flow and the Equals Count operator to set a count variable, that you then check.

Any greater than 1 and you know there are duplicates and you don't send the email. If this is the only record that matches your query, then it'll return 1 and you send the email alert.

I know you haven't asked for this but... things to be aware of with error logs

  • you might want to have a process that culls logs after a certain period of time or count of logs; otherwise they grow and grow...
  • when there are hundreds of thousands/millions of rows your queries will slow down; look at field indexing options
  • when there are many rows owned by the same owner (over 10k) you need to worry about data skew and queries failing
1
  • 1
    Works like a dream, and the additional hints are noted - we do have a process that deletes all records older than 30 days so the volume never gets very high.
    – Irene
    Sep 15, 2022 at 23:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .