function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
chikkuchikku 

Used getRecord method it throws error on console ,any resolved solution?

This my code i used(anything i need to modify,please let me know).
import { LightningElement, track, api,wire } from 'lwc';
import { getRecord,getFieldValue  } from 'lightning/uiRecordApi';
@track recType; 
@api recordId;
@track LjobsValue;
@track CjobsValue;
@track MjobsValue;
@wire(getRecord, { recordId: '$recordId', layoutTypes: ['Full'], modes: ['View'] })
    wiredRecord({data,error}) {
       if (data) { 
       var result = JSON.parse(JSON.stringify(data)); 
       this.recType=result.recordTypeId;
       this.LjobsValue=getFieldValue(data,'Loan__c.Total_Jobs_Lost__c');
       this.MjobsValue=getFieldValue(data,'Loan__c.Total_Jobs_Maintained__c');
       this.CjobsValue=getFieldValue(data,'Loan__c.Total_Jobs_Created__c');
       }
       else{
         this.error=error;  
         console.log(error);
       }
   }
i used this code it throws error in console

this cause error:User-added image
Best Answer chosen by chikku
David Zhu 🔥David Zhu 🔥

Then the lookup relationship field (Account__r)  is not valid.  You have to find out what is the field name in loan__c object setting.
You can try the following soql in developer console, and I think it will tell you such field not exist.

select id,account__r.name from loan__c

 

All Answers

Christan G 4Christan G 4
Hi Cibi, I hope you are well. I believe the line 11 is what's causing this error. It doesn't seem normal to parse a JSON thats been converted into a string. Have you tried outputting the result variable in console log and see what it shows?
David Zhu 🔥David Zhu 🔥
Your code looks good. You may check two points:
1. If Loan__c object has record type. if not, line 12 will err out.
2. Make sure Total_Jobs_Lost__c,Total_Jobs_Maintained__c,and Total_Jobs_Created__c are valid field on Loan__c object.
 
chikkuchikku
@christan yes i tried by removing the JSON file but same don't work it throws error same
chikkuchikku
@David so i need to remove the line 12 ? And yes that are all fields of loan__c object
Christan G 4Christan G 4
Hi Cibi, I found an article that was very similar to yours. I believe it’ll solve the issue you are having: https://developer.salesforce.com/forums/?id=9062I000000QwLGQA0
David Zhu 🔥David Zhu 🔥
@cibi, you need to remove line 12
David Zhu 🔥David Zhu 🔥
@cibi, or you can change line 12 if record type exists on Loan__c object.

this.recType=data.recordTypeId;
 
chikkuchikku
Thanks @David ,one more doubt i have look up relationship  loan with account object in that account object i have same fields there in loan.how to access i dont know ,u have idea?
chikkuchikku
Can we use like this to. Access look up relationship field's loan with Account object :- it this possible? @David
this.MjobsValue=getFieldValue(data,'Loan__c.Account__r.Total_Jobs_Maintained__c'); this.CjobsValue=getFieldValue(data,'Loan__c.Account__r.Total_Jobs_Created__c');
David Zhu 🔥David Zhu 🔥
If you have a lookup to Account, you can use  getFieldValue(data,'Loan__c.Account__r.Name'); to get accout name. same pattern for other fields in parent object.
chikkuchikku
It dosen't worked getFieldValue(data,'Loan__c.Account__r.Name'); @David
David Zhu 🔥David Zhu 🔥

Then the lookup relationship field (Account__r)  is not valid.  You have to find out what is the field name in loan__c object setting.
You can try the following soql in developer console, and I think it will tell you such field not exist.

select id,account__r.name from loan__c

 

This was selected as the best answer