---
schema_version: "1"
id: 2fd6af0199425906681effaeab52bee889e46258f465b227330cd206417764ea
title: Collection Sort Element
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/flow_ref_elements_sort.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.flow_ref_elements_sort.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 57d0e866ef9a7b2aafdc2d96651eb5a82fc43f1d5d6bfd6939c118fffb9b703a
description: Reorder the items within a collection and optionally limit the number of items that remain in the collection after the sort.
products:
  - Flow Builder
  - Salesforce Platform
release: "264"
---
# Collection Sort Element

Reorder the items within a collection and optionally limit the number of items that remain in the collection after the sort.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=platform.flow_ref_supported_editions.htm&amp;release=264.0.0&amp;type=5" title="Learn about the editions and user interfaces that support Flow Builder. Some Flow Builder features integrate with other Salesforce products that require additional licenses.">View supported editions.</a></td></tr></tbody></table>

 
| Field | Description |
| --- | --- |
| **Collection Variable** | The collection variable that is sorted. This field accepts any collection variable within the same flow. |
| **Sort By** | The field that the collection is sorted by. This field is only shown if the collection variable contains more than one field. |
| **Sort Order** | Sort the collection in ascending or descending order. |
| **Put empty string and null values first** | When selected, this element sorts records with an empty or null value in the Sort By field at the start of the collection. Otherwise, they’re placed at the end. |
| **How Many Items to Keep After Sorting** | Select **Set the maximum number of items** to determine the number of items that remain in the collection after the sort. |

## Usage

When the Collection Sort element removes values or changes their order, it makes those changes directly in the selected collection variable.

If the collection variable contains more than one field, click **Add Sort Option** to sort by additional fields in order of greater to lesser priority. You can sort by up to 3 fields at a time.