1

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

6
  • Did you check your browser console log to see for any exceptions? And what is being returned in accountData, can you paste that too. Jan 13 at 4:39
  • 1
    it should be this.OrderAlreadySubmitted();. I presume that's what you mean when you say it's not working? Or do you get a specific error message? Jan 13 at 5:55
  • I am not getting any error message. The page just doesnt show up. When I revert my code back (remove the new JS function) the pages start to show. (I put this js code to display a new page i added) Jan 13 at 15:23
  • I am getting an error message that the query is returning nothing. So The page just doesnt show up. When I revert my code back (remove the new JS function) the pages start to show. (I put this js code to display a new page i added). Thats why i think i am not passing the accId properly to the orderalreadysubmited function Jan 13 at 15:39
  • do you have a value in this.acId? Is paramValue working - 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 using window.location and look at properly doing query parameters for LWC Jan 13 at 18:29
0

You cannot reassign value to an api property. Please try adding another property with getter and setter to access the public property acId. I would also suggest to use CurrentPageReference from the navigation module to access the URL and URL Params as suggested by @Kris Goncalves.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.