5

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?
    – Raul
    Oct 20 '19 at 19:43
  • I want the records not the describes Oct 21 '19 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!
    – Raul
    Oct 21 '19 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?
    – JimRae
    Oct 22 '19 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 Oct 22 '19 at 13:33
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;
    }
}
}

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.