Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
edited tags
Link
Derek F
  • 64.2k
  • 15
  • 55
  • 104

Get the record Id from one LWC and use it toin another LWC

everyoneEveryone!

I'm currently practicing LWC.

I made an LWC1 that will create a new order (Order Object). And also created a different LWC2 to add product to the order created. Sadly, I can't add a new product since I'm not sure on how to get the record id (of the created id) of LWC1 and use it in LWC2. (If I'll combine the 2 LWCs, the LWC will actually run perfectly,. I just wanted to try if it is possible to run the LWCs separately).

Please see below for the codes:

Please see below for the codes (partial only):

LWC1 (Create New Order):

handleSuccess(event) { this.orderCreated = true; if (this.orderCreated) { getRecordId() .then(result => { this.recordId = result; }) }

event = new ShowToastEvent({ title: 'Success!', message: 'Order Created', }); this.dispatchEvent(event); }

handleSuccess(event) {
    this.orderCreated = true;
    if (this.orderCreated) {
        getRecordId()
        .then(result => {
            this.recordId = result;
        })
    }

    event = new ShowToastEvent({
        title: 'Success!',
        message: 'Order Created',
    });
    this.dispatchEvent(event);
}

LWC2 (Add Product):

addProduct(event) { this.getRecordId = event.detail; if (this.recordId == null || this.recordId == '') { alert('Please create a record first');

addProduct(event) {
    this.getRecordId = event.detail;
    if (this.recordId == null || this.recordId == '') {
    alert('Please create a record first');

Get the record Id from one LWC and use it to another LWC

everyone!

I'm currently practicing LWC.

I made an LWC1 that will create a new order (Order Object). And also created a different LWC2 to add product to the order created. Sadly, I can't add a new product since I'm not sure on how to get the record id (of the created id) of LWC1 and use it in LWC2. (If I'll combine the 2 LWCs, the LWC will actually run perfectly, I just wanted to try if it is possible to run the LWCs separately).

Please see below for the codes:

Please see below for the codes (partial only):

LWC1 (Create New Order):

handleSuccess(event) { this.orderCreated = true; if (this.orderCreated) { getRecordId() .then(result => { this.recordId = result; }) }

event = new ShowToastEvent({ title: 'Success!', message: 'Order Created', }); this.dispatchEvent(event); }

LWC2 (Add Product):

addProduct(event) { this.getRecordId = event.detail; if (this.recordId == null || this.recordId == '') { alert('Please create a record first');

Get the record Id from one LWC and use it in another LWC

Everyone!

I'm currently practicing LWC.

I made an LWC1 that will create a new order (Order Object). And also created a different LWC2 to add product to the order created. Sadly, I can't add a new product since I'm not sure on how to get the record id (of the created id) of LWC1 and use it in LWC2. (If I'll combine the 2 LWCs, the LWC will actually run perfectly. I just wanted to try if it is possible to run the LWCs separately).

Please see below for the codes:

Please see below for the codes (partial only):

LWC1 (Create New Order):

handleSuccess(event) {
    this.orderCreated = true;
    if (this.orderCreated) {
        getRecordId()
        .then(result => {
            this.recordId = result;
        })
    }

    event = new ShowToastEvent({
        title: 'Success!',
        message: 'Order Created',
    });
    this.dispatchEvent(event);
}

LWC2 (Add Product):

addProduct(event) {
    this.getRecordId = event.detail;
    if (this.recordId == null || this.recordId == '') {
    alert('Please create a record first');
Source Link

Get the record Id from one LWC and use it to another LWC

everyone!

I'm currently practicing LWC.

I made an LWC1 that will create a new order (Order Object). And also created a different LWC2 to add product to the order created. Sadly, I can't add a new product since I'm not sure on how to get the record id (of the created id) of LWC1 and use it in LWC2. (If I'll combine the 2 LWCs, the LWC will actually run perfectly, I just wanted to try if it is possible to run the LWCs separately).

Please see below for the codes:

Please see below for the codes (partial only):

LWC1 (Create New Order):

handleSuccess(event) { this.orderCreated = true; if (this.orderCreated) { getRecordId() .then(result => { this.recordId = result; }) }

event = new ShowToastEvent({ title: 'Success!', message: 'Order Created', }); this.dispatchEvent(event); }

LWC2 (Add Product):

addProduct(event) { this.getRecordId = event.detail; if (this.recordId == null || this.recordId == '') { alert('Please create a record first');