This we can do in three steps:
Step 1 Get Account
record data for that we need recordId
which we have.
Step 2 Now get Segment_ID__c
field value from account record.
Step 3 Finally get the loadPersonalizedOffers
with the Segment_ID__c
value.
Code will look something like this:
import { LightningElement, api, track, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';
/* ... */
import loadPersonalizedOffers from "@salesforce/apex/PersonalizedOffersController.loadPersonalizedOffers";
FIELDS = ['Segment_ID__c'];
export default class Personalized_offers extends LightningElement {
@api recordId;
@track account;
segmentId;
/* ... */
@wire(getRecord, { recordId: '$recordId', fields: FIELDS }) /* Step 1 */
getAccount({error, data}){
if (error) {
this.dispatchEvent(
new ShowToastEvent({
title: 'Error loading account',
message: error.body.message,
variant: 'error',
})
);
} else if (data) {
this.account = data;
this.segmentId = this.account.fields.Segment_ID__c.value; /* Step 2 */
/* Now we can call the getPersonalizedOffers */
loadPersonalizedOffers({Id: this.segmentId}).then((data)=> {
if (data) {
console.log(JSON.stringify(data));
}
}).catch((error)=> {
console.log(JSON.stringify(error));
});
}
}
/* ... */
}