Reply
Newbie
alana_
Posts: 2
0
Accepted Solution

Get salesforce logged in user

Hello,

 

I am using the OpenCTI API. One of the methods I could use to possibley obtain the logged in user of Salesforce is the method 'runApex'. So, I created an Apex class below. However, I am unable to get the user. Does anybody know how to successfully obtain the salesforce user from the Apex class. Any ideas?

 

global class GetCurrentUser{

    webService static String getUserName(String name) {
        System.debug('User Id: ' + UserInfo.getUserId());
        return UserInfo.getUserId();
    }
}

Regular Contributor
MJ Kahn / OpFocus
Posts: 42
0

Re: Get salesforce logged in user

Once you have the User Id (from UserInfo.getUserId()), you can use it to query the User object:

 

User u = [select Id, username from User where Id = :UserInfo.getUserId()]
MJ Kahn / OpFocus, Inc / www.opfocus.com
Regular Contributor
ibtesam
Posts: 88
0

Re: Get salesforce logged in user

+1 MJ

 

Once you get the id, following information can be queried using SOQL query.

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_user.htm

Newbie
alana_
Posts: 2
0

Re: Get salesforce logged in user

Thank you all for your response. It works.