with Code below I am trying to get account Id in the trigger for Quote.

trigger populateAccountAddress on Quote (after insert) {
System.debug('DEBUG 1:'+trigger.new[0].OpportunityId);
System.debug('DEBUG 2:'+trigger.new[0].Opportunity.AccountId);
System.debug('DEBUG 3:'+trigger.new[0].Opportunity.Account.Id);

DEBUG returns Opportunity ID (Fine) Rest of the two debug statements returns null.

Am i doing something wrong please guide. I know its possible to get Account IDs after collecting all Opp ids and then querying it for the same.

But trigger.new[0].Opportunity.AccountId i expected it to return Account ID.


1 Answer 1


In a trigger you only get the direct fields of the object in question. You don't get fields from related objects. So OpportunityId you do get but anything Opportunity. you don't get. You will need to query those if you require them.

  • This is true for most fields, but if you were unable to get the AccountId, how would you query for the Accounts? You must have access to the AccountID or you would have no way to query for them, right? Sep 23, 2013 at 12:16
  • From the quote you have the OpportunityID, you would build a set of OpportunityIDs and then query the Opportunity object to return the account IDs (or whatever else you wanted)
    – Doug B
    Sep 23, 2013 at 12:39
  • I'm sorry, you are totally correct. I was thinking in terms of a related object in a SOQL query, not in the context of a trigger. You're absolutely right, you need to query these objects Sep 23, 2013 at 13:51

You must log in to answer this question.

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