How to use both the Selected and the Edited records in a Datatable

See an updated version of this post here: Let’s Revisit How to use both the Selected and the Edited records in a Datatable

My Datatable Flow Screen Component allows a user to both Select records and make Edits to records.  The component returns two separate collection variables.  One of them includes the original values of just the selected records.  The other one includes just the edited records whether they were selected or not.

Sometimes, you may want to process just the selected records in your flow, but include the edited values in those selected records.  This sample flow shows how you can create a selected record collection with edits.  The flow loops through each of the selected records and if no edits were made to it, it gets added to the final collection.  If an edited version of the record is available, it gets added to the final collection instead.

Here’s the Select & Edit Screen Datatable displaying all of the Product records from an Opportunity.

I’ll select 3 records and make edits to 2 of them.

My final results show the 3 selected records with the edited fields included.


Let’s go through the steps you can follow to combine the outputs from the Datatable component. In this section, I’ll show you how each of the nodes in the flow is configured.

I start with an Opportunity record with an Id that is passed into the flow.  Whenever possible, let the flow Automatically store all field values.


All of the Opportunity Products are added to a Collection (OpportunityLineItem).


Because I am displaying a similar Datatable multiple times in this flow, I store my attributes in variables so they can be reused for each Datatable.


The Datatable is displayed using the attributes assigned earlier.  Here, the user can select and edit records.


I am manually assigning the outputs from the Datatable to new collection variables to make the steps in this flow more readable.


This loop will take us through each of the records in the collection of Selected records where we will perform the next few steps on each record.  New in Summer ‘20, the flow will automatically create a loop variable for you.


In this step, I look for a record in the collection of Edited records with the same Id as the current Selected record in the loop.  The “Find Records In Collection” Flow Action is part of a group of very powerful actions you can include in your flows to act on record collections.  The entire group can be found and installed from here.


The output from the Flow Action will be the matching record from the collection of Edited records if found, otherwise it will return a null value.  This Decision checks to see if that record was found.


When an Edited record is found, it is added to the final collection variable that we will be using for the rest of our flow.


When there is no matching Edited record, we use the Selected record from the Loop instead.


Whichever record we chose now gets added to the final collection variable.


After the end of the Loop, I display another Datatable with the values from the final collection variable.  This is just an example.  In your own flow you may be doing something here like adding updated products to a new renewal Opportunity or something else with the selected and edited records.


Links

DatatableV2
https://unofficialsf.com/datatablev2-lightning-web-component-for-flow-screens/

Collection Actions for Flow
https://unofficialsf.com/list-actions-for-flow/

Sample Flow (Install in Sandbox)
This includes DatatableV2 and FindRecordsInCollection
https://test.salesforce.com/packaging/installPackage.apexp?p0=04t2i0000005IWc

70 thoughts on “How to use both the Selected and the Edited records in a Datatable

  1. Hi Eric – Very nice utility.

    In this example you’re demoing update existing records.

    We’ve requirement to update and/or ADD new opportunity product records using flow.

    Can we add new opportunity product record using this utility?

    Like

  2. Hi Eric,

    thumbs up for your datatable v2. I just have one question: What is the best way to integrate your component into my Salesforce DX project?

    Using git clone and then copy your source code into my project?

    Deploy to my Dev Org, create an unmanaged package and then use sfdx force:package:install on my scratch orgs?

    Nevertheless, great work and thanks!

    Like

  3. Hi Eric,

    Thanks for an amazing component. I am trying to use the “Pre-Selected Rows” but having a hard time getting it to work. Here is my use case:
    I am using datableV2 to load records from a custom setting and have the user select one (or more) records for the next step in the flow. This is working perfectly. I also need to have one record to be pre-selected. So I added a “Get Records” element and filtered the returned rows to the one that I want. The other options in that “Get Records” are: All records, Automatically store all fields. I am using that in the datable V2 “Pre-Selected Rows”. But I still can’t get the row to be pre-selected. Am I doing this the right way? thanks!

    Like

      1. As per your suggestion, I changed it to a manually created variables and it is working now. Thanks for your help!

        Like

      1. Perhaps. The ideal would be if I could have the error message pop up on the screen after the Participating Individuals and Room is chosen, if they exceed the room capacity for total guests with that room reserved during the room’s dates. I posted a bit more about it here: https://trailblazers.salesforce.com/0D54S000008HImb. Thanks in advance for your help with this, Eric. Much appreciated.

        Like

  4. Hello Eric,

    First of all, many thanks for this component which is very powerful.
    I get an issue to edit fields of type number.
    My SF field is numeric (16,2). When I want to edit it in the table, it works when I enter 10,00 but it doesn’t work when I entered 10,01 (or 10.01). I click on Next and I am back to the table and again and again.
    You mention percent field cannot accept digits at the right of the comma but I have not read anything concerning decimal ?
    Tank you for your help and once again, Bravo !
    And Happy new year 2021

    Like

    1. I’m still unable to reproduce this behavior. Can you proivde some more detail about how you have configured the datatable and if this happens on both currency and numeric fields?

      Like

  5. Hello Eric,
    it’s working now on API version 51.
    Unfortunately, my Prod is on 50, I will wait the next version.
    Thank you

    Like

  6. Eric, this is a great tool – i have used it a ton, and love the improvements you continue to make to it.
    I do have a question – is there a way to determine the newly selected rows and only action on them? For instance i have an opportunity with line items preselected. in the flow, the datatable is pre-selected with the line items that were already chosen, but the user wants to add more line items to the opportunity. if i do this currently, i am either creating duplicates of the line items already selected (if i use the selected items collection) or i can only capture the edited line items (but not line items that were added, but not edited).
    I guess what i am looking for is if a change to the “selected” column could indicate an edit, just like a change to any other column….

    Like

  7. Hi Eric,

    Can you have a loop element immediately after the datatable screen? I created a manually assigned variable for “Output Edited Rows” but am getting ambiguous errors when I try to use it in a loop right away.

    Datatable Version: 3.0.10
    Example error: “Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details. Error ID: 1074418025-4895 (2127287436)”

    Thanks for the great tool!

    Like

    1. Yes, you can loop through either the Edited Rows or Selected Rows collections immediately after the Datatable screen. You could try adding a decision first to see if the collection is empty.

      Like

  8. Many thanks for your speedy reply. That, along with some other tweaks, seems to have moved us past the ambiguous error.

    Now have a question about entering percentages into the datatable:

    Is it a limitation of a Lightning Input field that a user can not enter “40” and have it reflect as “40%” (as a user can do in a standard Salesforce field)? Are there any workarounds for this that you know of?

    Like

  9. Hi Eric,

    Thanks again for this amazing tool. For some reason I’m unable to assign the variables (Edited and selected). It seems that “Edited” is not available. Am I missing something?

    Like

  10. You can forget y previous comment. I just figured it out. I was literally creating a collection for the wrong object (the objects I’m working with have a similar name). Thanks again

    Liked by 1 person

  11. Super nice component! I ran into an issue and am not sure what I am doing wrong. Essentially, I want to update the status of a selected record in the table.

    Currently, I am looping over the selection collection and then assigning the new status value to the status field of the current item in loop but somehow the records don’t really update when I subsequently use the Update Records element?

    Like

    1. If you are going to modify values in a record collection in a loop, I recommend that you don’t try to modify the loop collection variable. Make your changes to a record in the loop and then add that changed record to a new collection that you will pass to a Record Update after the loop.

      Like

  12. Hi Eric, I’m really excited to try some of this. I have installed datatable in both sandbox and production and in both cases am having issues with the “configure column” button. I get stuck with spinning dots and a “please wait…loading field details.” Any ideas to nudge me in the right direction? Thanks for putting this together and maintaining it.

    Like

      1. Thanks, it was the clickjack protection that was leading to the error. Appreciate your response!

        Like

  13. Pingback: ericsplayground
  14. I’ve had this deployed for a while but am now getting an error on any Read Only field: ‘Apex Action error: Field GrandTotal is not editable’ during the display at runtime and Configure Columns screen then the table doesn’t populate. Not seeing anything in the troubleshooting that applies.

    Like

  15. Hi Eric, after the user edit values on the table, on the next step, the {!OpportunityProducts.outputEditedRows} is empty. I’m I missing something? I tried to manually assign to a new collection variable but it didn’t work. I’m using the OpportunityLineItem object. I’m using v 3.3

    Thanks!

    Like

  16. Is there any road map to support validating the edited values in dataTable and making the particular field column as required?.

    Example: Current validation for Email is only checking if it contains ‘@’ and not for the valid format.

    Like

    1. The email validation you are referring to is the standard validation handled by Salesforce when editing an email field. It is not any alternate validation provided by the datatable component. Making a column entry required is a bit more complex and should be handled by the flow after the datatable screen. Are you looking to make just a single edit required in a column, all rows must contain a value, or something else? You can always display a message and navigate back to the datatable screen if your custom validation checking shows any exceptions.

      Like

  17. Hello –

    The Datatable Configuration Wizard doesn’t load for me and keeps spinning. I am in Sandbox as well. Am I missing a component or something?

    Like

    1. If you see this error when trying to Configure Columns, try going to Setup > Security > Session Settings and unchecking “Enable clickjack protection for customer Visualforce pages with headers disabled“. Also, in your Setup > User settings, make sure both Debug Mode and Development Mode are Unchecked.

      Like

    2. If you see this error when trying to Configure Columns, try going to Setup > Security > Session Settings and unchecking “Enable clickjack protection for customer Visualforce pages with headers disabled“. Also, in your Setup > User settings, make sure both Debug Mode and Development Mode are Unchecked.

      Like

  18. Hi Eric,
    I am trying to use Datatable in my flow to show all Facilities related to a Billing Group. But I want all facility records to show up as “Selected”. So I want all the boxes to the set to true. I can’t find the way to do that. Can you guide me through if this is possible through this component. Thanks.

    Like

  19. I love this and use it all the time!
    Just a question: If a user does not have edit permissions for a particular field I noticed that the data table will run and simply not update that field. Can the editability of the field reflect the edit rights that the user currently has? Ie. user does not have edit rights = little pencil will not show? Obviously if flow is in system context this wouldn’t apply.

    Like

  20. Hey, this was super helpful, but my requirement is a little different, when a user selects a row and edit a value and goes to the next screen, but when he goes to the previous screen the edited value is gone, how can we store the edited values and have the flow remember them. Thanks

    Like

      1. So, you are saying when the user selects a row and edit a value and hit next, I need to store that edited record collection and when the user hit previous I need to send edited record collection to the data table to show the edited values?

        Like

  21. Check the setting for the retain previous values for the screen. If changing that setting doesn’t work, you will need to hide the Previous button and add you own logic in the flow to control what happens when the user wants to go back.

    Like

    1. I was trying the Datatable component in my dev org. However, when I hit the configure columns button the page takes forever to load, in fact it never loads. Any issue with the component that you might know?

      Like

  22. Hi I am sending JSON String to DataTable, which gets displayed properly. However in order to me to get the selected row I am thinking of using outputSelectedRow. However, the value in that variable keep showing the first row in the list. Is there anything I need to change so that it has the value that I selected

    Like

  23. Hi
    Fully appreciate that I have missed something fundamental, but cannot spot it.
    I have a datatable with a number rows with some uneditable and one editable columns.
    I then go straight to a loop to assign the data from the selected records ready to create new records.
    I then edit the ediitable field, save, and select the row and click next.
    In Debug the section
    ‘numberOfRowsEdited = 1’
    ‘numberOfRowsSelected = 1’
    This string has the edited value.
    But further in the debug the ‘outputSelectedRowsString =’ has the unedited value.

    Moving to the loop this correctly picks up the selected rows, but when I try and assign the values to a variable in the flow I get the unedited value.
    The syntax I am using is:
    {!datatable.outputSelectedRow.MSA_Price__c}
    Where MSA_Price__c is the editable field column.

    As I said, I think I am missing something daft, but I cannnot spot it.
    Any help gratefully appreciated.

    Like

    1. The selected row will only have the original data passed into the component. You need to look at the output collection from outputEditedRows which will contain all of the edited rows. Even if there is only one record, you will need to pass the collection into a loop in order to look at individual records.

      Like

      1. Thank you Eric, is there a way to filter the selected rows to exclude any that are also in the edited list?
        Thanks

        Like

  24. I love the Datatable but the Search feature is problematic as it won’t “hold” the selected value when you search for other values to select. Is there any fix for this?

    Like

      1. Fixing the search to keep the selected fields would be a significant improvement. With the current behavior the Search field is unusable if you need to select more than one record. I look forward to this fix!!! :-)

        Like

  25. Love the datatable. I am trying to create Opportunity Products from a datatable of products from a price book. I can create one Opp Product from “Output Selected Row” but when I try to create multiple Opp Products from “Output Selected Rows”, it is not working.

    Like

Leave a reply to Johann Moulin Cancel reply