I am using the below code to make a call to apex method on page load and validate some response. I am getting error

afterRender threw an error in 'c:TestLWC' [Cannot read property 'data' of undefined]

@track recorddetails;
      @wire(getRecordDetails, { recordId: "$recordId" })
      validateresponse({ error, data }) {
        if (error) {
        } else if (data) {
          recorddetails= JSON.parse(data);



 <template if:true={recorddetails.data}>
   <template for:each={recorddetails.data} for:item="rr">
      <lightning-layout multiple-rows="true">
         <lightning-layout-item padding="horizontal-small" size="6">
            <p class="slds-text-title_bold">Owner:</p>

2 Answers 2


You should set a default value:

@track recorddetails = { data: [] }

And also, you generally don't need to parse the data. In addition, you need to use this to set the correct value:

this.recorddetails = data;

I feel there is two problem in code.

  • First one @sfdcfox has mentioned about putting this this.recorddetails = data;
  • Second one is template code - <template if:true={recorddetails.data}> looks like recorddetails is null and you try to access data on it so it is throwing [Cannot read property 'data' of undefined]. Change this to <template if:true={recorddetails}> should resolve issue.

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.