I have to admit its been a while since I wrote an LWC component. I have the HTML which basically loads a different page (view) depending on if a condition is true. There is one part of my JS which is not working and as a result it is no longer loading any of the pages. I believe I am passing the variable from the LWC to apex incorrectly. The parameter is the recordId (which is the accId). I am calling a JS function that passes this accountId to apex. The apex checks if that account has a certain field (Order_Confirmation__c which is a checkbox) as true or not. If it is, then it loads a page and if it is false it loads a different page. Everything was working great. Then I added the below piece of JS and now nothing is loading(obviously I am only providing that snippet which contains the JS function and not all JS for relevance). Here is my Apex:
global class ApexCtrl { @AuraEnabled global static Account getOrderSubmitted(Id accId){ Account acc = [SELECT Id, Name, Order_Confirmation__c, Feedback_Confirmation__c FROM Account WHERE Id =: accId]; return acc; } } Here is my JS for the LWC:
import { LightningElement, track, api } from 'lwc'; import { NavigationMixin } from 'lightning/navigation'; import AccountHasOrder from '@salesforce/apex/APEXCtrl.getOrderSubmitted'; export default class MylWC extends NavigationMixin(LightningElement){ @track virtualSellingFirst; @track virtualSellingThankyou; @track FeedbackThankyou; @track virtualSellingNoGUID; @track accountData; @track productRecord; @track error; @api acId; connectedCallback() { this.acId = ''; const param = 'c__recordId'; const paramValue = this.getUrlParamValue(window.location.href, param); console.log('to show my parm :: '+paramValue); //this.productNameGet(); if(paramValue == null || paramValue == ''){ this.acId = ''; this.virtualSellingFirst = false; this.virtualSellingNoGUID = true; }else{ this.acId = paramValue; OrderAlreadySubmitted(); //Am I calling this properly //this.virtualSellingFirst = true; //this.virtualSellingNoGUID = false; } } OrderAlreadySubmitted(){ AccountHasOrder({ accId: this.acId }) .then(result => { this.accountData = result; if(this.accountData.Order_Confirmation__c == true){ this.virtualSellingFirst = false; this.virtualSellingNoGUID = false; this.VirtualSellingThankyou = true; this.FeedbackThankyou = false; }else if(this.accountData.Feedback_Confirmation__c == true){ this.virtualSellingFirst = false; this.virtualSellingNoGUID = false; this.VirtualSellingThankyou = false; this.FeedbackThankyou = true; } else if(this.accountData.Feedback_Confirmation__c == true && this.accountData.Order_Confirmation__c == true){ //not sure if ths condition is needed this.virtualSellingFirst = false; this.virtualSellingNoGUID = false; this.VirtualSellingThankyou = true; this.FeedbackThankyou = false; } else{ this.virtualSellingFirst = true; this.virtualSellingNoGUID = false; this.VirtualSellingThankyou = false; this.FeedbackThankyou = false; } }) } } Can someone please let me know what I am doing wrong here? Thanks
accountData, can you paste that too.this.OrderAlreadySubmitted();. I presume that's what you mean when you say it's not working? Or do you get a specific error message?this.acId? IsparamValueworking - I would guess it isn't. Is this LWC within a different component or are you navigating to a specific URL for it? I would avoid usingwindow.locationand look at properly doing query parameters for LWC