Is there a way to get result from apex method if param is @api value (that comes from parent)?
like this:
@api trip; // comes from parent
@wire(getTickets, { recordId: '$trip.Id' }) tickets;
or how to pass this param?
Thank you!
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communityDefine a setter-getter for tripId
and use it to extract the @wire
configuration value.
Here's what that looks like:
tripId; // value to use with @wire
_trip; // private var used with getter-setter
@api
set trip(value) {
this._trip = value;
this.tripId = value.Id; // extract the value
}
get trip() { return this._trip; }
@wire(getTickets, { recordId: '$tripId' }) tickets;
This approach with a getter-setter is preferred over other solutions (eg a getter only on tripId) because it'll keep this.tripId up to date whenever this.trip is changed.
it works like that:
@api trip;
@track tripId;
@wire(getTickets, { recordId: '$tripId' }) tickets;
connectedCallback() {
this.tripId = this.trip.Id;
}
this.tripId
. tripId
is @api
so the parent component may change the value at any time.
Jul 17, 2019 at 15:04