• Piotr B
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies

Hi guys so im facing issue with getRecords adapter when i hard code to adapter configuration Ids of records it works but when i send a array of string as it is requierd data is not fetching 

 

import { LightningElement, api, wire, track } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { getRecords } from 'lightning/uiRecordApi';
import getResult from '@salesforce/apex/CustomUser.getResult';
const FIELDS = [
    'Result__c.Name',
    'Result__c.User__c',
    'Result__c.License_Proposal__c',
    'Result__c.Current_License__c'
];
const COLS = [
    { label: 'Id', fieldName: 'Id' },
    { label: 'Email', fieldName: 'Email' },
    { label: 'Current License', fieldName: 'Current License' },
    { label: 'License Proposal', fieldName: 'License Proposal' }
];
export default class TestCmp extends LightningElement {
    @api recordId;
    contacts;
    @track records = [];
    columns = COLS;
    testing = [];
    @wire(getResult)
    resultHandler({ data, error }) {
        if (data) {
            console.log(data);
            this.records = data;
            console.log(Array.isArray(this.records));
        } else if (error) {
            console.error(error);
        }
    }
    @wire(getRecords, {
        records: [
            {
                recordIds: '$records',
                fields: FIELDS
            }
        ]
    })
    wiredRecord({ error, data }) {
        if (error) {
            let message = 'Unknown error';
            if (Array.isArray(error.body)) {
                message = error.body.map((e) => e.message).join(', ');
            } else if (typeof error.body.message === 'string') {
                message = error.body.message;
            }
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error loading Result',
                    message,
                    variant: 'error'
                })
            );
        } else if (data) {
            console.log(data);
            this.contacts = data.results.map((item) => {
                return {
                    Id: this.getValue(item, 'User__c'),
                    Email: this.getValue(item, 'Name'),
                    'Current License': this.getValue(
                        item,
                        'Current_License__c'
                    ),
                    'License Proposal': this.getValue(
                        item,
                        'License_Proposal__c'
                    )
                };
            });
            console.log('i m here ' + this.contacts);
            // this.name = this.contacts.results[1].result.fields.Name.value;
            // this.phone = this.contacts.results[1].result.fields.Phone.value;
        }
    }
    getValue(data, field) {
        return data.result.fields[field].value;
    }

But if i give it ['a0*********QAU', 'a06**********AU']  instead of array of '$records' it works  

  • September 25, 2022
  • Like
  • 0

Hi guys so im facing issue with getRecords adapter when i hard code to adapter configuration Ids of records it works but when i send a array of string as it is requierd data is not fetching 

 

import { LightningElement, api, wire, track } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { getRecords } from 'lightning/uiRecordApi';
import getResult from '@salesforce/apex/CustomUser.getResult';
const FIELDS = [
    'Result__c.Name',
    'Result__c.User__c',
    'Result__c.License_Proposal__c',
    'Result__c.Current_License__c'
];
const COLS = [
    { label: 'Id', fieldName: 'Id' },
    { label: 'Email', fieldName: 'Email' },
    { label: 'Current License', fieldName: 'Current License' },
    { label: 'License Proposal', fieldName: 'License Proposal' }
];
export default class TestCmp extends LightningElement {
    @api recordId;
    contacts;
    @track records = [];
    columns = COLS;
    testing = [];
    @wire(getResult)
    resultHandler({ data, error }) {
        if (data) {
            console.log(data);
            this.records = data;
            console.log(Array.isArray(this.records));
        } else if (error) {
            console.error(error);
        }
    }
    @wire(getRecords, {
        records: [
            {
                recordIds: '$records',
                fields: FIELDS
            }
        ]
    })
    wiredRecord({ error, data }) {
        if (error) {
            let message = 'Unknown error';
            if (Array.isArray(error.body)) {
                message = error.body.map((e) => e.message).join(', ');
            } else if (typeof error.body.message === 'string') {
                message = error.body.message;
            }
            this.dispatchEvent(
                new ShowToastEvent({
                    title: 'Error loading Result',
                    message,
                    variant: 'error'
                })
            );
        } else if (data) {
            console.log(data);
            this.contacts = data.results.map((item) => {
                return {
                    Id: this.getValue(item, 'User__c'),
                    Email: this.getValue(item, 'Name'),
                    'Current License': this.getValue(
                        item,
                        'Current_License__c'
                    ),
                    'License Proposal': this.getValue(
                        item,
                        'License_Proposal__c'
                    )
                };
            });
            console.log('i m here ' + this.contacts);
            // this.name = this.contacts.results[1].result.fields.Name.value;
            // this.phone = this.contacts.results[1].result.fields.Phone.value;
        }
    }
    getValue(data, field) {
        return data.result.fields[field].value;
    }

But if i give it ['a0*********QAU', 'a06**********AU']  instead of array of '$records' it works  

  • September 25, 2022
  • Like
  • 0