Forcetrails: How to pass url parameter from lightning application to lwc

Hello Trailblazers!!

While I was trying to implement a custom form element in Lightning we component, I wanted to open that in Lightning Application so that I can see the immediate results as I save the changes instead of putting it directly on the record page of the object. Apparently, I was not able to get the record id from the Lightning Application to LWC. I tried to search for many articles, documentation on this but I was not able to find the solution to the problem. The problem was, I was not getting the record in Lwc which resulted to fail uiRecordApi.

Finally, I found the obvious solution which I was not getting in my head.

1. Created public reactive for recordId.
2. Created an attribute in my lightning application with name = id, you can give whatever you want.
3. Passed that id attribute from lightning application to Lwc as a merge field.

And, yes it solved my problem. I was able to get the record id in my Lwc and uiRecordApi worked.

Here is my sample Lightning Application "TestApp"
<aura:application extends="force:slds">
    <aura:attribute name="id" type="String"/>    
    <c:formExample recordId="{!}"/>

Here is the code for LWC - Html markup.
    <div if:true={}>
        <div class="slds-form slds-form-element_stacked">
            <div class="slds-form-element">
                <label class="slds-form-element__label" for="form-element-firstName">First Name</label>
                <div class="slds-form-element__control">
                    <input type="text" id="form-element-firstName" placeholder="First Name" class="slds-input"
                        value={firstName} />

            <div class="slds-form-element">
                <label class="slds-form-element__label" for="form-element-lastName">Last Name</label>
                <div class="slds-form-element__control">
                    <input type="text" id="form-element-lastName" placeholder="Last Name" class="slds-input" required
                        value={lastName} />

            <div class="slds-form-element">
                <label class="slds-form-element__label" for="form-element-email">Email</label>
                <div class="slds-form-element__control">
                    <input type="email" id="form-element-email" placeholder="Email" class="slds-input" required
                        value={email} />

            <div class="slds-form-element">
                <label class="slds-form-element__label" for="form-element-phone">Phone</label>
                <div class="slds-form-element__control">
                    <input type="phone" id="form-element-phone" placeholder="Phone" class="slds-input"
                        value={phone} />

Here is the code for LWC - JS Controller.
import {
} from 'lwc';
import {
} from 'lightning/uiRecordApi';
const fields = [
export default class formExample extends LightningElement {
    @api recordId;
    @track contact;
    @wire(getRecord, {
        recordId: '$recordId',
    get firstName() {
    get lastName() {
    get phone() {
    get email() {

Here is the code for LWC - Meta XML.
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="" fqn="formExample">

Here is how I passed the id to the TestApp.
Hope you guys like it!
Happy Coding!!!
No comments :
Post a Comment

Hi there, comments on this site are moderated, you might need to wait until your comment is published. Spam and promotions will be deleted. Sorry for the inconvenience but we have moderated the comments for the safety of this website users. If you have any concern, or if you are not able to comment for some reason, reach email us at