+ Start a Discussion
admintrmpadmintrmp 

User ID in hybrid app

Anyone know how to get the user ID in the hybrid application. I'd imagine there would be one of two options:

 

1. Get it from a stored variable somewhere in the application.

2. Use a command in REST API.

 

But how do we do it?

 

Thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
Kevin HawkinsKevin Hawkins

The SalesforceOAuthPlugin.getAuthCredentials() method will return an object with the current user's configured credentials, though asynchronously.  So you could make a call like this in your JS:

 

var myUserId;

function getCreds() {
    SalesforceOAuthPlugin.getAuthCredentials(successCallback, failCallback);
}

function successCallback(userCredentials)  {
    myUserId = userCredentials.userId;
}

function failCallback() {
    alert("Couldn't get auth credentials!");
}

 

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]

Kevin HawkinsKevin Hawkins

The SalesforceOAuthPlugin.getAuthCredentials() method will return an object with the current user's configured credentials, though asynchronously.  So you could make a call like this in your JS:

 

var myUserId;

function getCreds() {
    SalesforceOAuthPlugin.getAuthCredentials(successCallback, failCallback);
}

function successCallback(userCredentials)  {
    myUserId = userCredentials.userId;
}

function failCallback() {
    alert("Couldn't get auth credentials!");
}

 

This was selected as the best answer
Shaik JeelanShaik Jeelan
Nice post.. get best Good morning buddha quotes (https://statussove.com/good-morning-buddha-quotes/) to visit