Joseph Dindinger
Posts: 0
Joined: Sat Nov 30, 2013 12:27 am

Show only records owned by logged in user?

Using the standard Contact app as an example, how would I know which user is logged into Salesforce.com? The standard app returns all contacts that the user has access to, in my application I want to return only the records owned by the currently logged in user.

The login process happens in the SF_JSUtils Javascript provided, as shown below:

pre
function doLogin () {

Code: Select all

// as we render all pages into one file, let's check if this is a callback 
if (window.location.href.indexOf("access_token") == -1) { 

   var client_id = SF_Settings['client_id']; 
   var redirect_url = SF_Settings['redirect_url']; 
   var login_url = SF_Settings['login_url']; 

   var url = login_url + "?response_type=token&display=touch&display=touch&client_id=" +  
     client_id + "&redirect_uri=" + encodeURI(redirect_url); 

   // let's go to Salesforce to login 
   window.open(url, "_self");    
 } 
 else { // yes, this is a callback 
   // save token, url into local storage 
   saveAuthCodeInLocalStorage();  
   // navigate to page 
   Appery.navigateTo('mypage', {reverse: false}); 

 } 

}
/pre

I would imagine that the solution would be to grab the userid returned somewhere in the code above and store it in a local variable, which can then be used to create the SOQL call. But I cannot figure out how. I imagine this has been done before?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Show only records owned by logged in user?

Hello! Please check what data is returned by authorization service in Salesforce http://www.salesforce.com/us/develope.... If this data help you to do request you need, save it in saveAuthCodeInLocalStorage function in localStorage.

Joseph Dindinger
Posts: 0
Joined: Sat Nov 30, 2013 12:27 am

Show only records owned by logged in user?

No, unfortunately, that does not return the user ID. Has anybody done that before? I can't imagine I am the first to need this?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Show only records owned by logged in user?

Hi Joseph,

What errors do you see in console and in network tab in requests? Please post some screenshots.

Joseph Dindinger
Posts: 0
Joined: Sat Nov 30, 2013 12:27 am

Show only records owned by logged in user?

Hi Katya,

No errors. The problem is that all of the users see the same records. I want to filter on the records that they own, so that each user sees different records. Does that make sense?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Show only records owned by logged in user?

Hi Joseph,

You can change plug-in and Facebook example as you need. This documentation may help you, there are some examples of what you need: https://developers.facebook.com/docs/...

Joseph Dindinger
Posts: 0
Joined: Sat Nov 30, 2013 12:27 am

Show only records owned by logged in user?

Thank you for all your suggestions. It turns out that Maryna was correct at the beginning of the post. It WAS returning the correct information, I just was not seeing it.

Here is the final code, in case anybody every runs into this issue like I did.

pre
function saveAuthCodeInLocalStorage () {

Code: Select all

var url_params = []; 
var params = window.location.href.slice(window.location.href.indexOf('#')+1); 
params = params.split('&');    

for (var i in params) { 

   var item = params[i].split('='); 
   url_params[item[0]] = item[1]; 

   // find the ID for the current user 
   if(i == 2) { 
       var sUserID = item[1].substr(item[1].length - 18); 
       localStorage.setItem('user_id', sUserID); 
   }  
} 

 // save token with type: Bearer 
localStorage.setItem('access_token', 'Bearer ' + decodeURI(url_params.access_token)); 
// save service URL, needed to invoke services 
localStorage.setItem('instance_url', decodeURIComponent(url_params.instance_url)); 
// clear the token from URL 
//window.location.replace(SF_Settings['redirect_url']+"#");  

}
/pre

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Show only records owned by logged in user?

Joseph, thanks for sharing that.

Adi Argov
Posts: 0
Joined: Fri Nov 01, 2013 7:43 pm

Show only records owned by logged in user?

can you provide how/when and where you call saveAuthCodeInLocalStorage () ?
I tried after salesforceLogin(), but I don't get the ID back to storage.
Thanks for your help,

Pavan Varma
Posts: 0
Joined: Thu Mar 19, 2015 7:02 am

Show only records owned by logged in user?

Hi,
May I know where to call saveAuthCodeInLocalStorage () method. Please help me..

Return to “Issues”