5

Is there a way to specify the sort direction in the getRelatedListRecords wire adapter?

The Docs give the following example:

@wire(getRelatedListRecords, {
  parentRecordId: '001RM000003UNu6YAG',
  relatedListId: 'Contacts',
  fields: ['Contact.Name','Contact.Id'],
  sortBy: ['Contact.Name']
})

But there's no documentation on how to define the sortBy as ASC or DESC.

1 Answer 1

9

As per this documentation, You need to pass the - before the field name to get data in descending order.

If the name is preceded by -, the sort order is descending. For example, Name sorts by name in ascending order. -CreatedDate sorts by created date in descending order.

@wire(getRelatedListRecords, {
        parentRecordId: "001RM000003UNu6YAG",
        relatedListId: 'Contacts',
        fields: ['Contact.Name', 'Contact.Id'],
        sortBy: ['-Contact.Name']
    })
    listInfo({ error, data }) {
        if (data) {
            console.log("data:: " + JSON.stringify(data.records));
        } else if (error) {
            console.log("error:: " + JSON.stringify(error));
        }
    }
1
  • It's such an non-standard way of doing it.
    – Kelderic
    Commented Oct 10 at 12:16

You must log in to answer this question.

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