• About
  • Contact me!

Salesforce Everywhere

~ Blog on Salesforce Dev and admin stuff

Salesforce Everywhere

Tag Archives: onLoad

How to get field values on onLoad in lightning-record-edit-form in LWC?

03 Monday Jan 2022

Posted by Mani in Uncategorized

≈ Leave a comment

Tags

LWC, onLoad

Let’s say we are using lightning-record-edit form in LWC to display/edit the data and we have a requirement to get the field values during the onLoad event of the form.

For instance, onLoad event calls handleOnLoad method and the code below shows the right approach to get the field values from the form based on the recordId:

handleOnLoad(event) {
        var record = event.detail.records;
        var fields = record[this.recordId].fields;(obviously we need to have the recordId declared as @api decorator and the lwc is placed on the record page. Please refer the link https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.use_record_context to read more about it)
        const assetName = fields.Name.value;      
        alert(assetName);
}

We can use template.querySelector as well(as given below), but it is not the right approach(rather not a good approach):

handleOnLoad() {
    let name = this.template.querySelector('.name').value;//in the html, we should have given class="name" for the name field
}

Hope this post is helpful and let me know for any questions. Thanks!!

Advertisement

Blog Stats

  • 114,771 hits

Archives

Recent Posts: Salesforce Everywhere

How to get field values on onLoad in lightning-record-edit-form in LWC?

Using Dynamic Actions

How to check if the logged in user is a Guest user or not in APEX class?

How to Close Quick action in LWC

Lightning component to filter Products and display results in lightning data table

Connect with me

  • View @manibalan_s’s profile on Twitter
  • LinkedIn

Developer links

  • Salesforce Developer website
  • Salesforce Success Community

Enter your email address and click on Follow us (below) to follow this blog and receive notifications of new posts by email.

Website Powered by WordPress.com.

  • Follow Following
    • Salesforce Everywhere
    • Already have a WordPress.com account? Log in now.
    • Salesforce Everywhere
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar