Get UserId from the Session Id and Server URL

2020-01-19 04:25发布

问题:

I have a requirement, where I will be getting the Session Id and Server URL(parameters of a webservice method).

Say like this:

Session ID : 00D900000xxxxxx!ARUAQOb4VVoQR1UXlY_Hvuy1DdKdN6nSfnNJKYwPTF9R3tYuA2jzBsWXHIGDQUFL13iebnYSDKKC45H98TzVxxxxxxxxxx

Server URL : https://ap1.salesforce.com/services/Soap/u/12.0/00D900000xxxxxx

Now i need to get the User Id(or any other user details) from these two.

Thanks in Advance!!

Nitin

回答1:

You could use the SOAP API, which has a GetUserInfo method. Calling this method will return a GetUserInfoResult object, which will contain the user ID associated to the session.



回答2:

Adam, GetUserInfo method requires existing connection object which we can create by calling method, so I applied the following code and now everything works fine!

ConnectorConfig config = new ConnectorConfig(); config.setAuthEndpoint("https://login.salesforce.com/services/Soap/c/24.0/"); config.setServiceEndpoint("https://na14.salesforce.com/services/Soap/c/24.0/00DXXXXXXXXXXXX"); config.setSessionId("00DXXXXXXXXXXXX!1AQ4AQO980Fmu25SOFQxxOlQN8zAaHOlnfdk._rZU2Vkf_CV0HJREqKavMLaPg9jtA9N517MNHLdLeF.aVkoZtnk2eu7u.XNn"); connection = new EnterpriseConnection(config); GetUserInfoResult userInfo = connection.getUserInfo();

I used the same server URL and sessionId that I have received from query parameter string.