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
raj345raj345 

UserInfo Salesforce

How do I get the id of the user with Rest APi?

Best Answer chosen by Admin (Salesforce Developers) 
Tom GersicTom Gersic

You don't want to call Phonegap.exec in your success callback. What you probably want there is something along the lines of:

 

function success(response){
console.log(response.userId);
}

All Answers

Tom GersicTom Gersic

It's returned in the oauth login response URI

 

access_token=[ACCESS TOKEN (Session Id)]

&refresh_token=[REFRESH TOKEN]

&instance_url=https%3A%2F%2Fna1.salesforce.com

&id=https%3A%2F%2Flogin.salesforce.com%2Fid%[ORG ID]%[USER ID]

&issued_at=1312403866216

&signature=[SIGNATURE]

raj345raj345

Hi, 

 

Thanks for your response.


var SalesforceOAuthPlugin = {

/******************************************************************************************************************************
* Obtain authentication credentials, calling 'authenticate' only if necessary.
* Most index.html authors can simply use this method to obtain auth credentials
* after onDeviceReady.
* success - The success callback function to use.
* fail - The failure/error callback function to use.
* PhoneGap returns a dictionary with:
* accessToken
* refreshToken
* clientId
* userId
* orgId
* loginUrl
* instanceUrl
* userAgent
*****************************************************************************************************************************/
getAuthCredentials: function(success, fail) {
PhoneGap.exec(success, fail, "com.salesforce.oauth","getAuthCredentials",[]);
},

 

In the document, they said that we can get the user id using getAuthCreadentials. I am trying to get the user id using the below method.

 

SalesforceOAuthPlugin.getAuthCredentials(success, getAuthCredentialsError);

function success(){
PhoneGap.exec(getAuthCredentials(userId()));
}

 

When I run the app, it says

 

getAuthCredentials called

getAuthCredentials successful

Error in success callback: com.salesforce.aouth3 = ReferenceError: userId is not defined at file:///android_asset/www/phonegap-1.2.0.js:773

Tom GersicTom Gersic

You don't want to call Phonegap.exec in your success callback. What you probably want there is something along the lines of:

 

function success(response){
console.log(response.userId);
}

This was selected as the best answer
raj345raj345

Thanks for your response Tom. Its working now.