5

I am following a guide for how to get a specific record type for when creating a lightning-record-edit-form and I am getting this error thrown:

enter image description here

My Html looks as follows:

<lightning-record-edit-form object-api-name={caseObject}  onerror= {ShowToastEventFailure} onsuccess={ShowToastEventSuccess} record-type-id={recordTypeId}>
    some fields/grids here
</lightning-record-edit-form>

JS looks as follows:

import { LightningElement, api, wire, track } from 'lwc';
import { getRecord, getFieldValue, getObjectInfo } from 'lightning/uiRecordApi';
import CASE_OBJECT from '@salesforce/schema/Case';
import Id from '@salesforce/user/Id';
import NAME_FIELD from '@salesforce/schema/User.Name';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';



const fields = [NAME_FIELD];

export default class Culinaryrequest extends LightningElement {
    userId = Id;
    caseObject = CASE_OBJECT;
    @api objectApiName;
    @track objectInfo;

    @wire(getRecord, { recordId: '$userId', fields })
    user;

    @wire(getObjectInfo, { objectApiName: CASE_OBJECT })
    objectInfo;

    get name() {
        return getFieldValue(this.user.data, NAME_FIELD);
    }

    get recordTypeId() {
        const rtis = this.objectInfo.data.recordTypeInfos;
        return Object.keys(rtis).find(rti => rtis[rti].name === 'Culinary Team Request');
    }

    ShowToastEventSuccess () {
        const event = new ShowToastEvent ({
            title: 'Success!',
            message: 'Your Request to the Culinary team has been submitted',
            variant: 'success',
        });
        this.dispatchEvent(event);
    }

    ShowToastEventFailure () {
        const event = new ShowToastEvent ({
            title: 'Oh Noes! :(',
            message: 'Something is wrong with your Request please check that all required fields are filled out. If the problem persists please open a case with Real Estate Technology',
            variant: 'failure',
        })
        this.dispatchEvent(event);
    }

}

If anyone has any ideas why this is being thrown please let me know as I am new to LWC and would love to learn!

3
  • Are you getting this error when adding the component in App Builder?
    – Jayant Das
    Commented Apr 4, 2019 at 19:21
  • Yea, after its added to a App Record Page
    – scarecrow
    Commented Apr 4, 2019 at 19:28
  • I got the issue you were facing, added the details in answer. Hope it helps.
    – Jayant Das
    Commented Apr 4, 2019 at 21:41

2 Answers 2

8

After trying to replicate your issue (which I was able to), it turned out that your issue is on this import line:

import { getRecord, getFieldValue, getObjectInfo } from 'lightning/uiRecordApi';

You have the wrong adapter here lightning/uiRecordApi for getObjectInfo resulting in all the issue where objectInfo never gets populated thus returning that error.


To fix this, getObjectInfo needs to be imported from lightning/uiObjectInfoApi as below:

import { getObjectInfo } from 'lightning/uiObjectInfoApi';

I used the example in this documentation as a reference while trying to identify the resolution.

9
  • I did that and I am now getting a different error, afterRender threw an error in 'c:culinaryrequest' [Cannot read property 'recordTypeInfos' of undefined] (Yay) I tried seeing if specifying the object in @wire(getObjectInfo, { objectApiName: 'Case' }) would fix it but it did not. Any ideas?
    – scarecrow
    Commented Apr 5, 2019 at 14:49
  • 1
    if you have a new error, you might wan to open a new post to avoid extended discussions in the comments.
    – glls
    Commented Apr 5, 2019 at 15:09
  • @Jayant Das that didnt not fix it, I tried Glls approach of added an error handler and it looks like the first time it gets called both error and data are undefined, the second time it gets time it gets called it has a data property (with recordtypeInfos) but for some reason calls the else if (error)
    – scarecrow
    Commented Apr 5, 2019 at 15:15
  • @scarecrow You can actually use it that way. However it just works fine with what you have here. I though removed the not relevant things viz., User fields, etc. and it just works fine. You may be having some other issue here. Take a look at the documentation link that I have referred there, that should help.
    – Jayant Das
    Commented Apr 5, 2019 at 15:15
  • 1
    @JayantDas figured it out! not having <div if:true={objectInfo.data}> caused it to error out, I am guessing it was due to what frup42 was mentioning with race conditions?
    – scarecrow
    Commented Apr 5, 2019 at 15:42
1

Its very likely that there is an error that you are not catching.

If an error occurs in the adapter, for example when retrieving the data, error is populated with an error object AND data is set to undefined.

A quick suggestion would be to instead of wiring your response to a property, do it to a Function:

Wiring a function is useful to perform logic whenever new data is provided or when an error occurs.The wire service provisions the function an object with error and data properties, just like a wired property.

this would at least allow you to throw an error that is meaningful, Ex:

 @track record 
 @track error;
 @wire(getObjectInfo, , { objectApiName: CASE_OBJECT })
    wiredCase(error, data) {
        if (data) {
            this.record = data;
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.record = undefined;
        }
    }
5
  • I just realised I missed some info in my question I have edited it to reflect the actual error, getRecord is working. What I am having issues is with getting the record type Id of the specific object
    – scarecrow
    Commented Apr 4, 2019 at 18:22
  • the error message implies that your data is undefined, so, it would seem natural that you can't fetch recordTypeInfos
    – glls
    Commented Apr 4, 2019 at 18:24
  • @glls It turned out to be an incorrect import for getObjectInfo thus the objectInfo property was never populated, resulting in the error.
    – Jayant Das
    Commented Apr 5, 2019 at 13:30
  • 1
    yes - i saw +1 =) , I merely suggested the OP to add error handling to their code, since, its not being captured.
    – glls
    Commented Apr 5, 2019 at 13:32
  • @glls I literally ended up copying line by line and trying to troubleshoot by process of elimination with the example in the documentation until found that :)
    – Jayant Das
    Commented Apr 5, 2019 at 15:08

You must log in to answer this question.

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