4

According to documentation, Lightning Data Services is built on top of UI API. So my question is: How I do to user Get Child Records UI API?

2
  • Nothing. I just created an Apex AuraEnabled method to return the records and wire up on the frontend with wire function
    – Saulo
    Jan 17, 2019 at 12:53
  • I was expecting to have something similar to import { getRecord } from 'lightning/uiRecordApi'; (with the name likely to getChildRecord) so bringing child records into component with something like @wire(getChildRecord, { recordId: '$recordId', fields }).
    – Saulo
    Jan 17, 2019 at 12:57

2 Answers 2

1

You should be able to do this using the getRecordUi wire adapter and specifying a childRelationships parameter:

import { LightningElement, wire } from 'lwc';
import { getRecordUi } from 'lightning/uiRecordApi';

export default class Example extends LightningElement {
  @wire(getRecordUi, { recordIds: '123', childRelationships: "Account.Opportunities" })
  myRecord;
}

Note that layoutTypes and modes are still required

2
  • 10
    This seems to be one of the biggest myths about this feature! childRelationships is not an attribute of getRecordUi! I don't know why everybody is referencing it from each other! Copy pasting it from others does not make it true. It does actually not have any effect on the result of getRecordUi.
    – Basti
    Sep 4, 2019 at 17:45
  • Agree... Important feature missing here Sep 22, 2019 at 11:20
0

It looks like the answer to this is coming to us in Spring 22 in the form of lightning/uiRelatedListApi (important to note - this will be in beta).

From the Release Notes:

This module includes new wire adapters to get records, metadata, and record count for a related list.

  • getRelatedListRecords—Returns record data for a related list.
  • getRelatedListInfo—Returns metadata for a related list.
  • getRelatedListsInfo—Returns metadata for multiple related lists.
  • getRelatedListCount—Returns the record count for a related list.

The example code they provide:

import { LightningElement, wire } from 'lwc';
import { getRelatedListRecords } from 'lightning/uiRelatedListApi';

export default class LdsGetRelatedListRecords extends LightningElement {
@wire(getRelatedListRecords, {
parentRecordId: '001RM000003UNu6YAG',
relatedListId: 'Contacts',
fields: ['Contact.Name','Contact.Id']
})
}

Keep in mind because this will be a Beta feature, it may not make it to general availability, so I wouldn't start putting it in production code in the event they axe this. Hopefully not though because this'll be a really useful feature.

EDIT: Still in beta but the documentation is now available. This is the example code included:

// wireGetRelatedListRecords.js
import { LightningElement, wire } from 'lwc';
import { getRelatedListRecords } from 'lightning/uiRelatedListApi';
export default class WireGetRelatedListRecords extends LightningElement {
    error;
    records;
    @wire(getRelatedListRecords, {
        parentRecordId: '001RM000003UNu6YAG',
        relatedListId: 'Contacts',
        fields: ['Contact.Id','Contact.Name']
    })listInfo({ error, data }) {
        if (data) {
            this.records = data.records;
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.records = undefined;
        }
    }
}
2
  • The example code here doesnt even work (it doesnt wire the record to any actual variable or function) and hopefully the docs will come for this but in the meantime there appears to be more parameters than listed anyway - it seems similar to the api here: developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/… Jan 20 at 13:29
  • @ChrisAbraham Hopefully they clean it up soon. They have a link to documentation for the new module but because it's not the current release the link's broken at the moment. Once that's working I'll likely be able to update my answer with more info. Jan 20 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.