6

I have a lightning web component that needs to call UI API. I can't use the LWC wired adapters because the 'getRecordUi' does not take the "childRelationships" parameters like the 'record-ui' endpoint does.

This childRelationships parameter allows me to get the top record as well as the childRecords from different relationships in a single call. For example get an account with related contacts and opportunities in the same call.

Unfortunately calling the Salesforce API directly is not permitted through LWC or Apex called by LWC (session id not valid). So, the alternative solutions are:

  1. Connected App with User/Password auth

  2. Dirty workaround to display the accepted session id from VF and then do a getContent() from apex.

As an ISV, if I select the first one I can't find a way to automatically deploy this connected app with my package (without configuration needed on the clients side). I really don't want these steps to be done manually especially when the only purpose of it is to call their internal Salesforce API. Is there an alternative solution ?

If I select the second one (which works fine), is the security review going to be approved ?

BTW questions asked on partners community but no luck for now.

6
  • Hi Lucas, What information of from childRelationships do you need, is describe call by apex not sufficient for your use case? Commented Oct 20, 2019 at 19:43
  • I want the records not the describes Commented Oct 21, 2019 at 14:25
  • Still not 100% clear on what is the problem, your question seems related to API call which is not possible as you have mentioned. Would suggest you to edit your question with more information on what you want to achieve, that may get some better answer or suggestions. Good luck! Commented Oct 21, 2019 at 20:06
  • If you just want the records, you could use an AuraEnabled apex method and wire that into your component. Or is this supposed to be more generic than that, and you don’t know what children your customers would have against the component? Commented Oct 22, 2019 at 1:53
  • @Raul I updated the question by adding: 'This childRelationships parameter allows me to get the top record as well as the childRecords from different relationships in a single call. For example get an account with related contacts and opportunities in the same call.' Thanks for you help hope you understand better my issue now Commented Oct 22, 2019 at 13:33

2 Answers 2

1

Even though your question is about when wire adapters don't exist - it's important to note that with Spring '22, there is a lightning/uiRelatedListApi in beta that exists now for your situation. It provides getRelatedListRecords so you should be able to get child records off of Account

Parameters

  • parentRecordId— (Required) The ID of the parent record that you want to get related lists for, like an Account ID.
  • relatedListId— (Required) The API name of a related list object, like Contacts, Opportunities, or Cases
  • fields—(Optional) The API names of the related list’s column fields
// 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; } } } 
0

if you follow this pattern for getRecord you should see the fields for related records:

import { LightningElement, wire, track, api } from 'lwc'; import { getRecord, getFieldValue } from 'lightning/uiRecordApi'; // This traverses the Salesforce Schema to get the Managers ReportsTo information import CONTACT_REPORTSTO_REPORTSTO_ID from '@salesforce/schema/Contact.ReportsTo.ReportsTo.Id'; import CONTACT_NAME_FIELD from '@salesforce/schema/Contact.Name'; import CONTACT_IMAGE_FIELD from '@salesforce/schema/Contact.Picture__c'; export default class MyComponent extends LightningElement { @track contact; @api recordId; @wire(getRecord, { recordId: '$recordId', fields: [CONTACT_NAME_FIELD, CONTACT_IMAGE_FIELD] optionalFields: [CONTACT_REPORTSTO_REPORTSTO_ID] }) getContactData({ error, data }) { if (data) { this.contact = data; this.error = undefined; } else if (error) { // TODO handle error this.contact = undefined; } } } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.