简体   繁体   中英

How to retrieve account object through SOQL Query

I have an account field(lookup field to account) and a user lookup field called ALO on contact object.What I want to do is to find out the account name field value on contact object, traverse that account, fetch the owner id and then assign that to the ALO field on the contact object.

This is what I have written in my apex controller but I am getting some syntax error maybe because of the API names that I am using. Can anybody help, please?

public Account acc {get; set;}

     acc = [ SELECT Id, OwnerId
                        FROM Account
                        WHERE Id =: contact.Account
                        ];

     contact.ALO= acc.OwnerId;

where 'contact' is the current contact instance.

Since ALO is a custom field you will have to append __c to the API name to access it. It would be contact.ALO__c = acc.OwnerId .

Also, you should be querying the AccountId field on Contact. Otherwise you will be getting an "No such column 'Account' on entity 'Contact'." error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM