I have created a custom button on the detail page of the event object and passed the record id in the URL but I'm not able to get the get that id in the LWC component as you can see in the screenshots. please guide me on this how to get the record id so that I will be able to display the event object fields to update by the user.
-
Please try this link salesforce.stackexchange.com/questions/331688/…– Ankit BansalApr 14 at 11:34
2 Answers
You should be able to have record Id in
recordId
variable in js file. Check this Trailhead - https://trailhead.salesforce.com/content/learn/projects/lwc-build-flexible-apps/single-record . You should have<targets> <target>lightning__RecordPage</target> </targets>
in your js-meta.xml file. Then in js file you have
@api recordId;
and record Id magicaly apear there.You always can use standard js to get params from a URL - https://www.w3docs.com/snippets/javascript/how-to-get-url-parameters.html
-
Hi Andrii, thanks for your response and I already tried this way but the record id is undefined in the console log Apr 13 at 21:19
-
you have to get your recordId from the url using connected callback.
new URL(url).searchParams.get('recordId');