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
pp11222pp11222 

How to get User's Account Id witouut querying the User Record

I want to know if is there a way to get the customer portal user's account id witout querying the User object for the the customer portal user.

 

Also what is the best way to find out if the logged in user is an customer portal user.

 

I could not find a system method to get account id using UserInfo.

 

Thanks

 

 

SFFSFF

Sorry, there isn't anything on userInfo for AccountId - that would be nice, though!

 

You can put a formula field on the User record to pick up the User's Contact's AccountId, although that just makes the query simpler, it doesn't remove the need for it.

 

If a User has a value in the Contact field, that is a portal user.

 

Good luck!

yvk431yvk431
I know this post is very old but in case if anyone have the same question:

For retriving the AccountId there is no other way we have to query for it. If you ever had to check whether the logged in user is a portal user then we have a way with out querying. We do have a field called usertype and its available through userinfo directly.

For customer portal user type is 'CustomerSuccess' for partner portal the usertype is 'PowerPartner' and you can retrievethe usertype from Apex as given below:
UserInfo.getUserType()


--yvk