1

I have an lwc action button that loads the popup. When i load the component for first time, recordId is present. But when i close and open it again(without reloading the whole page), recordId is lost. Kindly advise

export default class EmeaSubmitEvalRequest extends LightningElement {
_recordId;

@api set recordId(value) {
    this._recordId = value;
    console.log('in setter',this._recordId);
}

get recordId() {
    return this._recordId;
}
constructor(){
    super();
    console.log('constrcu',this.recordId);//not printed at all
}
connectedCallback(){
    console.log('connected recid',this.recordId);//not printed at all
}
@wire(invokeMuleService) 
getDropdownOptions({error,data}){
   if(data){
    this.defaultValues();
   }
}


   @wire(fetchExistingValues,{'evalId':'$recordId'}) preLoadValues({error,data}){
//do some logic here
}
6

1 Answer 1

-2

Just create @api variable like this:

@api recordId;

and use this in wire method like:

@wire(fetchExistingValues, { evalId: "$recordId" })

preLoadValues({error,data}){

//do some logic here

}

handleClick() {

fetchExistingValues({recId: this.recordId})

.then(function(res){ })

}

1
  • If you read the comments, you would have noticed that the OP solved it, but (unfortunately) didn't create an answer. Why should the original question be solved by using a simple variable instead of set/get? This reduces, not enhances reactivity. Or what have I overlooked?! Commented Mar 29 at 14:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .