0

I am creating a page that have record Id passed as a URL param.

And I'm getting it using:

@wire(CurrentPageReference) pageRef;
opp; 

get currentPageReference() {
    return this.pageRef ? JSON.stringify(this.pageRef, null, 2) : '';
}

get recordId() {
    return this.pageRef && this.pageRef.state.c__recordId ? this.pageRef.state.c__recordId : '';
}

In my opinion, that looks too ugly and a lot of code for getting a single URL param, but it works. recordId can be referenced in a component if I will do something like

RecordId = {recordId}
.

The problem is, I have no idea how to properly pre-load a record itself for the page. Last thing that I've tried:

get opportunity() {
    const recordId = this.pageRef && this.pageRef.state.c__recordId ? this.pageRef.state.c__recordId : '';
    if (!this.opp) {
        getOpportunity({recordId})
            .then((result) => {
                this.opp = result.data;
                this.error = undefined;
            })
            .catch((error) => {
                this.message = undefined;
                this.error = error;
            });
    }
    return this.opp;
}

with the getOpportunity as an apex method.

And if I will do something like

    <div>
        <p>{opportunity.Agreement_Type__c}</p>
    </div>

it will give me an error.

1 Answer 1

1

This is where you should use a secod wire

@wire(getOpportunity, { recordId: '$recordId' })
record;
1
  • 1
    thanks that helped!
    – RomanK
    Jul 12, 2022 at 11:29

You must log in to answer this question.

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