I'm trying to set orderId before I call displayOrderProducts(). Even though I'm calling the method to set orderId before the method it is used in, it seems to reverse the order:
console:
orderId-------2------- undefined
orderId-----1--------- a093S000001QjyyQAC
.js:
import { LightningElement, api, track, wire } from 'lwc';
import orderProducts from '@salesforce/apex/ResourceListController.orderProducts';
import getOrder from '@salesforce/apex/ResourceListController.getOrder';
export default class ResourceAssignForListPage extends LightningElement {
@api recordId;
orderId;
@track orderProductsList;
@track objectApiName = 'Order_Product__c';
setOrderId() {
getOrder({recordId: this.recordId})
.then(data => {
this.orderId = data.Id;
console.log('orderId-----1---------',this.orderId);
})
.catch(error => {
console.log(JSON.stringify(error));
});
}
displayOrderProducts() {
this.orderProductsList = [];
console.log('orderId-------2-------',this.orderId);
orderProducts({recordId: this.orderId})
.then(data => {
data.forEach(record => {
this.orderProductsList.push(record);
});
})
.catch(error => {
console.log(JSON.stringify(error));
});
}
connectedCallback(){
this.setOrderId();
this.displayOrderProducts();
}
}
I would expect the console.logs to be in opposite order. Any help appreciated.