0

This seems like a super simple question but I can't find the answer for the life of me. I have an app that is going to edit records in a new Lightning App Page with a Lightning Web Component in it.

When I go to this App Page, the Id is being passed as a URL parameter.

How do I get the value of a query string parameter in the js file of a Lightning Web Component?

  • please update your post with the code you have tried and where you are stuck exactly =) thanks – glls Apr 16 at 16:44
  • I don't have much code yet, I'm just starting and trying to figure out how to get the value of a query string parameter. – alex Apr 16 at 16:49
  • get the value of a query string parameter in what context? lighting communities, LEX ? – glls Apr 16 at 16:50
  • 1
    Not to sound rude but a simple google search on 'get record id in LWC' would have answered your question. Something like this developer.salesforce.com/docs/component-library/documentation/… – devforce Apr 16 at 17:07
  • You are correct, and I did find that, but that I think that only applies to record pages not app pages. – alex Apr 18 at 15:49
0

You simply need to specify recordId as an @api member, and the framework will give you the ID automatically.

// testClass.js
import { LightningElement, api } from 'lwc';
export default class TestClass extends LightningElement {
    @api recordId;
}

You should also be able to access window.location.search to identify parameters.

  • Thank you. I think @api recordId only works for Record pages, but you reminded me that I had been way overthinking the solution and I could use basic JS functionality to get what I needed. – alex Apr 16 at 17:38

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.