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
Ed055Ed055 

QUery help

I need help with writing query. I have a contact and that contact is related to an account which has a parent account(one level hierarchy) . I want to write a sosql query  to get the parent account ID if I pass contact ID. 

Thanks for help.
Jigar.LakhaniJigar.Lakhani
Hello,

Please try with below query
Replae your original contact in query.
Contact objContact = [SELECT ID, Name, AccountId, Account.ParentId FROM Contact WHERE Id = '003G0000027c3RL' LIMIT 1];
System.Debug('######## ' + objContact.Account.ParentId);

You will get parent account id in system debug log.

Thanks & Cheers,
Jigar