0

I have an opportunity (child) with a lookup borrower__c to account (parent). How can I query the account record,given opportunity record I'd without using borrower__r or borrower__c ?

2

@CommonCoreTawan is correct. I don't understand why you need to do this without using the "borrower__c" or "borrower__r field".

Considering you want to only use the opportunity Id and NOT Borrower__r. You could use a nested query such as the following which uses the Opp Id as you requested.

Id oppId = '0061I00000gdjafRQR'; 

List<Account> liAccount = [SELECT Id, .... FROM Account WHERE Id IN (SELECT Borrower__c FROM Opportunity WHERE Id =:oppId)];
1
  • My guess is that it's probably a test question or something, like for an interview or a certification exam. Otherwise, I'm not sure the purpose of the restriction on borrower__r either.
    – Roti
    Oct 18 '19 at 21:31
1

You can query the account fields in two ways

SELECT borrower__r.Name,borrower__r.Industry FROM Opportunity WHERE Id = 'myid'

or and query the object directly filtering by the account id on the opportunity

SELECT Name,Industry FROM Account WHERE Id = :opportunityRecord.Borrower__c

Not the answer you're looking for? Browse other questions tagged or ask your own question.