0

I'm trying to remove a single record from a record collection variable in a record triggered flow with the setup below, but the Remove All operator isn't working as expected.

The use case is for accounts to have an up to date count of their children accounts using the standard Parent Account field (No_of_children_accounts__c). The idea is that when the Parent Account field is updated, it will fire the flow (which runs after save) to count the total children accounts. There are two parts to this, first update the No_of_children_accounts__c field on the new parent, and then on the previous parent (when/if an account is reparented). The first part works fine, but the second part is where the issue is. So here's what I'm doing for the second part:

  1. Get Records - to get all children of the previous parent ($Record is being included in this account record collection, even though the $Record has a new parent at this point, not sure why this is happening)
  2. Assignment - to count the number of children accounts from #1 above
  3. Assignment - to remove $Record from the record from the collection obtained in #1 above (accountRecordCollectionVariable -- Remove All -- $Record)
  4. Assignment - to count the number of children accounts after step #3 above (there is no change here, the count still includes $Record)
  5. Update Record - to update the filed No_of_children_accounts__c for the previous parent.

So that should be pretty straightforward, but for some reason the removing of the $Record from the collection is what is not working. I have other ways to get around this (using a text Id collection variable instead, simply removing one from the count, etc) but for now:

What I am asking for help is specifically understanding why this is not working and what I need to change to remove a record from a collection

Thanks in advance for any and all help!

get records element assignment element to remove record from collection

1
  • I am still not sure why the removal of a record didnt work, but I'm inclined to think it was related to running the flow in rollback mode, since the changes are not yet committed to the database. In the end I opted to simplify this flow with just a Get Records, Count Records, Update field with record count (which did not work in debug but does work when activated) Commented Oct 16, 2023 at 18:03

1 Answer 1

1

I had the same problem. I solved it in a very simple way - added a condition in the Get records element (Id does not equal $Record.Id) to exclude the triggering record from the collection.

1
  • Good point Anna, that would do it. I think I had solved this some other way I can't remember now but your approach is probably simpler than whatever I ended up doing Commented Jul 4 at 20:07

You must log in to answer this question.

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