function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nitin tronixdevNitin tronixdev 

Unable to Fetch Account Lookup Field In Contact Value From Other Object

Hello,

I have a object in which a lookup field connected to Contact standard object .

for e.x.
field name is emp__c i.e.. lookup datatype

when i write emp__r.Phone in sql query i got phone number from contact object of a particular employee
similary when i write emp__r.Site__c i got all site's value from contact object of a particular employee

but 


when i try to fecth account from contact object i got null value like:-
emp__r.Account

to check my query i also created a custom lookup field in contact  which is connected to account
when i write  
emp__r.Acc__c...
Still i get null values..

why??

Its very urgent pls reply ASAP.

I can fecth any other value from contact using relation field other than account only ...
but i want account from contact object 
 
Chandra Sekhar CH N VChandra Sekhar CH N V
Try using emp__r.Account.Name
Abhishek BansalAbhishek Bansal
Hi Nitin,

Please try this :
emp__r.AccountId
This is the correct syntax for using Account field from contact.

Thanks,
Abhishek.
Kannan N 10Kannan N 10
Since Account is another object, You need to first reference the specific Record and then the field inside it... So, it will be emp__r.Account.xxxxx.   Try it by creating a cross object formula field and test it out.
Nitin tronixdevNitin tronixdev
Thanks to all every one's method has worked but can any one pls explain me , why this has happened...

when i fecth site__c from account i wrote emp__r.site__c
but for account why i need to  write emp__r.Account.Name
Chandra Sekhar CH N VChandra Sekhar CH N V
In salesforce we  use <sobject/child relationship>.<field/parent object > when accessing relation ship fields. Account is a standard object with API namesame as object name, giving only emp__r.Account won't return you anything as you are not accessing any field from account object yet from that expression. Salesforce will treat 'Account' itself as a field and since it does not exists, throws you an error.

So the correct way would be emp__r.Account. <your field>
Nitin tronixdevNitin tronixdev
Ohkay ... thanks every one ... i have also posted a query related to approval process can any one please repond to it too...

 
Chandra Sekhar CH N VChandra Sekhar CH N V
Glad you got that !!!

Also, as a best pratice you can mark the best answer in the post so that it will be helpful for other developers who comes across it.