+ Start a Discussion
Jos VervoornJos Vervoorn 

Account.Name, ERROR at Row:7: Column:13 Didn't understand relationship 'Account' in field path. If you are attempting to use a custom relationship .... // // please reference your WSDL or the describe call ..

When I try to compile it get the following error:

Account.Name, ERROR at Row:7: Column:13 Didn't understand relationship 'Account' in field patch. If you are attempting to use a custom relationship .... // // please reference your WSDL or the describe call ..

This refers to the following line ....

               List<User> lstUser = [SELECT 
            Id, 
            ContactId,
            Email,
            Username,
            AccountId, 
            Account.Name, 
            Profile.Name,
            FROM User 
            WHERE Id = :UserInfo.getUserId()];

Using Workbench I can simply use the query and it returns results. I also check field level security on the name field in the account but all profiles have access.Class btw this line is in is still in API v35 .. but I don't think that is causing the issue.
Best Answer chosen by Jos Vervoorn
Jos VervoornJos Vervoorn
 ... strange .. as when I adjust the query to the following ... it's compiling without error.

SELECT 
            Id, 
            ContactId,
            Email,
            Username,
            contact.AccountId, 
            contact.Account.Name, 
            Profile.Name
            FROM User 

All Answers

anka lexanka lex
Hi Jos,
 List<User> lstUser = [SELECT 
            Id, 
            ContactId,
            Email,
            Username,
            AccountId, 
            Account.Name, 
            Profile.Name
            FROM User 
            WHERE Id = :UserInfo.getUserId()];

please try this.. mark as answered if your query resolved.

Thanks,

 
Jos VervoornJos Vervoorn
No, same error btw ...
 
HARSHIL U PARIKHHARSHIL U PARIKH
I think we cannot directly query account records from User obejct.

Here is what I would suggest,
 
List<User> IstUser = [Select ID, ContactId, Email, UserName, AccountId, Profile.Name FROM User WHERE Id =: USerInfo.getUserId()];
    
List<Account> relatedAccounts = [Select Id, Name FROM Account WHERE Owner.Id =: IstUser[0].Id];

Hope this helps and if it resolves the question then please mark it solved!
 
Jos VervoornJos Vervoorn
Thanks, HARSHIL, however, why does this run in production without any problems and when I now compile in a full sandbox ... I get this error ... Even other sandboxes do no give this error .. only our UAT. Could it be due to the installation of some managed packages ...?
Jos VervoornJos Vervoorn
 ... strange .. as when I adjust the query to the following ... it's compiling without error.

SELECT 
            Id, 
            ContactId,
            Email,
            Username,
            contact.AccountId, 
            contact.Account.Name, 
            Profile.Name
            FROM User 
This was selected as the best answer