Use Case: Mass Update Records From Related List #1
Have you heard of inline editing? This is my favorite feature that I use EVERYDAY! Though amazing as it is, there are still limitations. For example, you can only edit records with the same record type, and it is only available in the list view but not in the related list. So today, we will introduce a mysterious “ids” variable to mass update records in related lists! It will not be as flexible as inline editing, but better than nothing I would say. (Or let’s all upvote this idea :D)
Why mysterious you wonder? This ids variable is similar to recordId. If your flow has this variable, Salesforce will also auto-populate it, but with multiple ids! What?! However, there are some important notes:
The Magical “ids” Variables
- This variable is not documented officially, so you can only know when you are in an exclusive club. (Joking. I did a lot of searching.)
— - Because of reason 1, there is a risk that it can break. (My first testing didn’t work at all)
— - It only works with related lists/list views that have checkboxes in the front.
— - The setup of the variable has to be EXACTLY like below.
—
Let’s dive in on how to set this up!
* Big thanks to Jaime from Viajes BIDtravel for sending in the case, and to Peter from Findock for sharing his thoughts!
Lulu Mobile uses the standard Account and Case object to keep track of their customers’ cases. Sometimes there can be many cases under one account, and they want to be able to mass edit the cases right from the related list to boost productivity.
Even though we can get multiple ids at once, they still exist as a collection variable. To edit each record, we will have to use loop to unpack the collection. That means we have to choose between two outcomes:
- Mass update the same fields with the same value for each record
— - Update the record one record at a time on the screen
—
We will introduce outcom#1 in this article and have a separate article about outcome#2. Lastly, we will launch the solution as a List View button, and it works on both related list and list view.
Comparison for the two flows:
See the pros and cons of two flows and choose the one that suits you the best.
Flow#1 (This Article) | Flow#2 | |
---|---|---|
Pros | + Less elements in Loop so better performance + Can skip the Done Screen and use retURL | + Can see the current value of each field + Can modify each record separately |
Cons | – Cannot redirect back to original Account page | – Longer process time and more screens |
Comparison for different solutions when there is only one record:
This solution can work even if you only want to edit one record. Then it will be similar to the solution in this article – Add Clone Button To Related List. Here is the comparison of two different methods:
List View Button (This Article) | Formula | |
---|---|---|
Pros | + Good looking UI + Can handle multiple records | + Easier to reach + Can have other field values fed to input variables |
Cons | – Always has to use Loop even for one record only | – Can be confusing as it is a field on object |
Screen Flow | Assignment | Variable/Collection |
Loop | Update Records | Input Variable |
Screen Element |
Does the solution solve your problem? If not, write us what your problem is and we will build the flow for you!
Hello, Melody! Does using the “ids” variable mean that you have to give users the “Manage Flows” permission to enable them to run the flow? Or are they able to run it with just the “Run Flow” permission? I created a flow similar to yours, except instead of mass updating records, they are being mass submitted for approval. The only way a user can run the flow is if they have “Manage Flows” on their profile. “Run Flow” is not enough, and I am wondering if that’s due to the “ids” variable. What is your experience? Thank you in advance!
Hi Nia, I tested with a Standard User profile with “Flow User” checked and the user is able to run the flow to mass delete records, so I think the error might not be from the ids variable. (I wish there could be more documentation on this)
Could it be the permission issue on the approval submissions? Were there any error logs that could help you trouble-shoot?
Nice trick! Note I’ve found even better results by using URLFOR within the button code. It returns the user back to the Account on flow completion instead of a generic case listing and works well in classic or lightning.
Using your example, the button code would be:
This is awesome, thanks !
Would it be possible somehow that all related records are chosen by default?
So in other words, i just want to push the button and don’t need to check the records on the related list
Hi Jan, I don’t think records can be chosen by default with ids variable. If you want to include all related records, I would recommend creating the button on the parent record instead. However, you will then not be able to unselect any record.
If you want to select everything by default while keeping the editability, I suggest looking into the datatable component from unofficalsf.com. Hope this helps!
thanks, i will look into the datatable component
Hi! Love your tutorials! Curious if you could help me understand how this could be rewritten for changing the owner on Contacts? I’m getting stuck in step 8 – there is seemingly no CurrentContact > Owner field for me to save the Add Updated Case to collection part too.
Thanks Suzy! Sure, but I am a bit unsure if I understood the issue. If you want to rewrite this flow for contacts, the variables from step 5&7 have to be created for contacts instead. Then in step 8 you will add the variable from step 5 into the collection from step 7. If this doesn’t help, kindly send over some screenshots and we can troubleshoot together
Hi Melody,
Thanks for this, its a great solution and worked perfectly for a use case I required.
I wondered if there are any considerations you are aware of if I wanted to use this flow to also mass-update a lookup field on the records? I’ve built the flow as above and it works for updating a checkbox, however I tried also adding a lookup screen component and getting a weird issue where an error message displays. If I hit the Next button it duplicates the lookup component and the error message each time. Any advice would be greatly appreciated! Thanks in advance
Hi Joe, no problem and thanks for the nice words! I am not aware of any existing issues. If you like, you can send me some screenshots of your flow and we can troubleshoot together.
Thanks Melody, I appreciate that – good news, it was just me being dim! Simple issue with the custom button I built. I can confirm the flow now works perfectly for my use case so thank you very much!
That’s nice to hear Joe! Glad that the issue is resolved:)
Hi, nice use case. I have created a flow myself where i used the ids variable and have a button on a list view. Working as above approach
Uses goes to list view, selects a number of cases and clicks on the button.
The flow will then loop through the ids and using a record singel variable set some fields (status = spam, type = junk, etc) then add that to a record collection variable and update and voila. All cases are updated!
But then i experienced a problem which i would like to solve.
Problem:
The list view shows all cases the user has access to (read) but not all of the cases the user has edit permission. So when the user chooses some cases where he/she doesn’t have edit access and click on the button he/she will receive: INSUFFICIENT_ACCESS_OR_READONLY: insufficient access rights on object id
Which i understand why of course, but how to handle this?
I also had a button on the page layout just for one case with the same functionality (only then you don’t use ids but you use recordId. In this case i used the UserRecordAccess object (see screenshot) and works like a charm (using a screenflow i could then add a screen and warn the user he/she doesn’t have edit access)
https://developer.salesforce.com/docs/atlas.en-
us.api.meta/api/sforce_api_objects_userrecordaccess.htm
Now my question is how can i use this UserRecordAccess object for the list view button with the ids variable?
Any idea?
Hi Eiyu,
Thanks! This is a really good question. Right now I am not seeing a way that we can handle this in bulk, meaning that you will have to use the Get Records inside the loop for each record to check whether it’s editable. If you decide to implement this, you will also have to be careful that a user doesn’t choose for more than 100 records at a time to avoid hitting the governor limits. Hope this helps!
Yes i was afraid so and not best practise, then again if its’s the only solution at this time i think it should do. A list view usually shows only 50 records at once so perhaps it can be done.
Also what can be done is just easy count the ids and if above 100 then show a message ” too many records selected ” or something similar.
As last comment, can you explain the number 100 ?
Sure. It’s because of the governor limits. Since you have to query the UserRecordAccess for each record in the selection, it will cost one SOQL each. The limit of SOQL queries for one flow is 100. (So to be more concise, if you use SOQL in other places of your Flow, this number has to be even lower to prevent hitting the limit)
Hope this helps!
Mhm sorry i tried but i think i don’t understand it in the end.
I have a loop where collection variable is {!ids} (list view records)
I then should do a get record for “UserRecordAccess object”
But how to configure this ?
GET RECORDS: Get Record Access list view
Find all UserRecordAccess records where:
RecordId Equals {!Loop_Cases} (5007Y00000HV7p7QAD)
AND HasEditAccess Equals true
AND UserId Equals {!$User.Id} (0051v000004KpCn)
Store the values of these fields in Get_Record_Access_list_view: Id
Result
Failed to find records.
And recordId must be specified in that get “UserRecordAccess object” otherwise it will also throw an error
Edit: related to this perhaps? : https://trailblazer.salesforce.com/issues_view?id=a1p3A0000018Bl6QAE&title=in-flow-can-t-perform-lookup-recordlookup-fastlookup-on-userrecordaccess-object&fbclid=IwAR3-jLHFHCNjr-c7xpJGIhYSIK-ztC65tRACKv6zfWNAElBjBUEC3W4WmfM
Or is it me?
Another really good spot! It is the same known issue, and the details can be found in the first post that you shared:
https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/sforce_api_objects_userrecordaccess.htm
(See the SOQL restrictions)
If we query with recordId, userId, and one access level, we can only return the recordId. However the default option always return Id as well and that’s why it’s throwing an error.
To fix this, you can create a text variable (AccessRecordId), and then configure the Get Records as screenshot. (Remember to check the box below)
Then you can use this text variable to write the Decision (If null: no edit access; if not null: has edit access)
Hope this helps!
Initially, I faced the Assertion Failed: Descriptor Flow Lightning Runtime error. I have enabled the flow to run in lightning runtime only. Not sure, if others faced the same issue.
I switched to classic and triggered the button from there and it worked. Switched back to lightning and it started working. Similar issue and solution mentioned in the below link:
https://trailhead.salesforce.com/pt-BR/trailblazer-community/feed/0D54S00000A7xILSAZ
Hey, I’m having trouble following these instructions. I think I have it set up correctly – collection variable titled ids available for input, loop, and update, launched from custom list button with url content source and sidebar-less behavior… but the ids don’t seem to be entering the flow when I activate it and test it on some real related list records.
I even added some display text to the first screen to display {!ids} so that I could see if any of them were being inputted, but {!ids} keeps turning up blank on the screen, and nothing actually happens when the flow finishes running.
Any advice on what I’m doing wrong?
Update (several weeks later) I still don’t know what was wrong, but I made an identical new flow from scratch and it worked just fine. I’m bamboozled, but at least it works now!
I see one issue with the following approach:
If the user leaves a field blank on the input screen, it will overwrite the existing value for the selected records with NULL.
Ex : Number of Days was set to 4,5,6,9 for the 4 records selected and on the Input screen the user didn’t populate the Number of Days field. So, once the process ends, the values 4,5,6,9 will be replaced with NULL, which may not be the desired output.
good afternoon, I have a question — using a similar concept as outlined in your post but instead of mass updating records, do you know how to select one or multiple records from a related list and create new records on a different object?