I am doing query on Opportunity from controller to Access account field detail but i am only getting Account Id not any other field.

[select  Id, AccountId, Account.name From Opportunity where id in : OppId]

I am getting

USER_DEBUG [1]|DEBUG|saddsa Get Event(Opportunity:{AccountId=001R000000v6FQbIAM, Id=006R0000009aIxEIAU, RecordTypeId=0120000000097UYAAY, CurrencyIsoCode=USD})

Here i am not getting Account Name while i am getting these value in query editor.

  • 1
    try to debug with relationship name.. in simple debug log it will not display but if you debug the relationship name then it will display. for example system.debug('----'+objOpportunity.Account.Name);
    – Ratan Paul
    Commented May 3, 2016 at 12:12
  • Thanks Ratan i am able to access it by objOpportunity.Account.Name
    – RaviKant
    Commented May 3, 2016 at 12:30

1 Answer 1


I believe related fields are not held within the trigger.new context if that is how you are accessing.

You should try something like this

for (Opportunity opp : [select Id, AccountId, Account.name From Opportunity where Id =: Trigger.new]){

 You can then access Account.name in here

You must log in to answer this question.

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