0

Currently I'm able to fetch all required fields from Opportunity as shown below:

import STAGE from '@salesforce/schema/Opportunity.StageName';

Similarly I need to fetch the Account fields which is linked to current opportunity but it is not working. This what I've tried:

import OPP_ACCOUNT_MY_CUSTOM_FIELD from '@salesforce/schema/Opportunity.AccountId__r.MyCustomField__c';

And I'm using getRecord() to fetch the Opportunity record as shown below:

const fields = [STAGE, OPP_ACCOUNT_MY_CUSTOM_FIELD ];   
@wire(getRecord, { recordId: '$recordId', fields })oppId;

Trying to access the data with getFieldValue() as shown below:

let myCustomField = getFieldValue(data, OPP_ACCOUNT_MY_CUSTOM_FIELD );

What should be changed in the import to make this work?

1 Answer 1

1

Try changing

import OPP_ACCOUNT_MY_CUSTOM_FIELD from '@salesforce/schema/Opportunity.AccountId__r.MyCustomField__c';
 

To

import OPP_ACCOUNT_MY_CUSTOM_FIELD from '@salesforce/schema/Opportunity.Account.MyCustomField__c';
2
  • 3
    You should explain why this fixes the issue. Standard lookups are SomethingId and the relationship is then just Something while custom lookups are Something__c and the relationship is Something__r.
    – Phil W
    Commented Dec 8, 2022 at 7:17
  • I do not believe getRecord can access related object fields directly either.
    – Phil W
    Commented Dec 8, 2022 at 8:55

You must log in to answer this question.

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