Collection Sort Element

 

  • Collection Sort Element

     This is new in Spring '22

    In this screen flow, we will use the collection sort to sort the records we have already retrieved with our get records element - to get the related contacts to an account.

    Yes - we could have sorted the results from the Get Records element, but in this case, we are just interested in how the collection sort works.

    We take advantage of not only the sorting capability of this element but also its capacity to apply the SOQL LIMIT clause to limit the number of records retrieved after sorting them.

    First, we need a recordId variable to pass the ID of the current account record across to the flow.

    Note: We have defined this as a record, NOT as text as this is a better way and can save us having to do a get records later. In this flow example it really does not matter but it's a good habit to get into for future flows.

    Get the contact records that are related to our Account record.

    Now we use the collection sort element.

    The first parameter is the collection from our Get Records.

    Next, we sort them by last modified date (ascending) to get the last modified records first.

    Finally, we set the number of records we want to keep. All the other records are removed from the collection, leaving us with just 3 records.

    To display these records, we use the Datatable component from Eric Smith. If you have not installed this component before then head over to unofficialsf.com and install it (and all it's dependencies).

    https://unofficialsf.com/datatable-lightning-web-component-for-flow-screens-2/

    Add a new screen element.

    Drag the Datatable component onto the canvas.

    Configure the Datatable as follows:

    Click Configure Columns:

    Select the fields you want to display in the table:

    You can adjust the width and other column settings if needed then click Done.

    Save and activate your flow.

    Click Debug and select an account record that has 3 or more contact records:

    Your flow will display the last three (3) contact records that have been modified.

    Try updating some contacts and then run the flow again to see the results.

    If you wish you can add this flow to your Account lightning record page.

No comments: