You need to sign in to do that
Don't have an account?
Manish.Singh
Display Record in LWC
Hi Everyone,
I want to display contact record in LWC but show me error.
Apex:
@AuraEnabled(cacheable=true)
public static contact getContact(string recordId){
return [SELECT FirstName,LastName,Account.M2BF_Company_Key__c,Email FROM Contact WHERE Id=:recordId];
}
LWC.js
import { LightningElement, api, track } from 'lwc';
import getContact from '@salesforce/apex/M2BFCreateCoachHandler.getContact';
export default class M2BFRegisterCoachLWC extends LightningElement {
@api recordId;
@track contactRec;
renderedCallback() {
this.handleload();
}
handleload() {
getContact({ recordId: this.recordId })
.then(result => {
alert(JSON.stringify(result));
this.contactRec = result;
})
.catch(error => {
console.log(error);
});
}
}
lwc.html
<lightning-input type="text" data-id="txtFirstName" value={contactRec.FirstName} label="First Name" required="true">
</lightning-input>
data collected from server side(apex) but while binding in html, it shows undefined.
Please help
Thanks
I want to display contact record in LWC but show me error.
Apex:
@AuraEnabled(cacheable=true)
public static contact getContact(string recordId){
return [SELECT FirstName,LastName,Account.M2BF_Company_Key__c,Email FROM Contact WHERE Id=:recordId];
}
LWC.js
import { LightningElement, api, track } from 'lwc';
import getContact from '@salesforce/apex/M2BFCreateCoachHandler.getContact';
export default class M2BFRegisterCoachLWC extends LightningElement {
@api recordId;
@track contactRec;
renderedCallback() {
this.handleload();
}
handleload() {
getContact({ recordId: this.recordId })
.then(result => {
alert(JSON.stringify(result));
this.contactRec = result;
})
.catch(error => {
console.log(error);
});
}
}
lwc.html
<lightning-input type="text" data-id="txtFirstName" value={contactRec.FirstName} label="First Name" required="true">
</lightning-input>
data collected from server side(apex) but while binding in html, it shows undefined.
Please help
Thanks
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
If you want to get data from same UI then youu don't need to write a Apex class. please follow below link for more clear
https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.data_wire_example
if you need any assistanse, Please let me know!!
Kindly mark my solution as the best answer if it helps you.
Thanks
Mukesh
similar to this: and then returning field with getter
reference:
https://developer.salesforce.com/docs/component-library/documentation/lwc/lwc.data_wire_service_about