You need to sign in to do that
Don't have an account?
Linda 98
SOQL to get account id related to my contact and account contact role's
I want to query all accounts on which my contact(logged in user) is having contact role too.
EG:
I have two accounts A,B and one contact C
C is contact of account A but has contact role on ACCOUNT B
So this is what i want to query,i have to get account A and B on my account look up field.
I am following this blog.But struck here with the query..
http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/
please help!!
EG:
I have two accounts A,B and one contact C
C is contact of account A but has contact role on ACCOUNT B
So this is what i want to query,i have to get account A and B on my account look up field.
I am following this blog.But struck here with the query..
http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/
please help!!
May be you can run another SOQL on AccountContactRole.
Queries may be like -
contactAccounts = [SELECT AccountId FROM Contact WHERE Id = :con.Id];
contactRoleAccounts = [SELECT AccountId FROM AccountContactRole WHERE ContactId = :con.Id];
or
contacts = [SELECT AccountId, (SELECT AccountId FROM AccountContactRole) FROM Contact WHERE Id = :con.Id];
If this is for a portal user (as your post suggests), you may first want to obtain the Id of Contact associated to the logged in user -
conId = [SELECT ContactId, AccountId FROM User WHERE Id = :UserInfo.getUserId()].ContactId;
In this case you don't need to query Contact object again as the query on User object can provide the parent Account's Id too. So you will need to query on User and AccountContactRole instead.
If none of the answers helped you significantly, please post the solution. You may also mark your solution as the best answer.