You need to sign in to do that
Don't have an account?
sroberts_ME
Current users account Id
Hi all,
I'm trying to figure out how to find the Id of the account the current user is associated with. I want to limit a query to find only records associated with that account. I thought there was a $User.account or something, but there doesn't seem to be. Any ideas?
Thanks,
Sam
No there is no direct way of this,
You have too fetch it from contact for current user.
ID contactId = [Select contactid from User where id =: Userinfo.getUserid()].contactId;
ID AccID = [Select AccountID from Contact where id =: contactid].AccountId;
All Answers
Hi Sam,
A user can be associated with an Account (I think you mean to say Standard Account Object) by several ways.
User can be the Owner of the Account
Can be the Creator of the Account
Can be the Last modified by person.
There can be some custom relationship, based on the system configuration as well.
Based on your business login you need to develop the SOQL and need to put LIMIT.
There are no such user global static properties to access the Account as there relationship is not of that type.
Thanks,
Dinesh Nasipuri
dinesh.nasipuri@gmail.com
No there is no direct way of this,
You have too fetch it from contact for current user.
ID contactId = [Select contactid from User where id =: Userinfo.getUserid()].contactId;
ID AccID = [Select AccountID from Contact where id =: contactid].AccountId;
try
[Select contact.AccountId from user where id =: Userinfo.getUserid()];
You can use
string strAccId = [select accountId from user where id=:userinfo.getuserid()];