You need to sign in to do that
Don't have an account?

Using SDK for Angular Bootstrap Node - How can I limit query with ownerId=User.Id?
All of the queries on the sample apps have no Where clauses. I need to put in a Where clause that limits the query to ownerId= the current user id.
I'm not sure how to capture the current UserId and what that would look like.
Here is what I have tried.
I edited this function in angular-force.js
function salesforceSessionRefreshed(creds) { // Depending on how we come into this method, `creds` may be callback data from the auth // plugin, or an event fired from the plugin. The data is different between the two. var credsData = creds; if (creds.data) // Event sets the `data` object with the auth data. credsData = creds.data; SFConfig.client = new forcetk.Client(credsData.clientId, credsData.loginUrl); SFConfig.client.setSessionToken(credsData.accessToken, apiVersion, credsData.instanceUrl); SFConfig.client.setRefreshToken(credsData.refreshToken); //added to get UserID var userId = credsData.userId; //Set sessionID to angularForce coz profileImages need them self.sessionId = SFConfig.client.sessionId; callback && callback(); }
And then I edited app.js with this where clause, on a custom object.
angular.module('Store', []).factory('Store', function (AngularForceObjectFactory) { //Describe the store object var objDesc = { type: 'Retail_Store__c', fields: ['Retailer_Store_Type__c', 'Account_Related_to__r.Name', 'Address_1__c', 'City__c', 'State__c', 'Phone__c', 'Field_Team_Tier__c', 'Lat__c', 'Long__c', 'Location_Note__c', 'Id'], where: 'ownerId='+userId, orderBy: 'Account_Related_to__c', limit: 20 }; var Store = AngularForceObjectFactory(objDesc); return Store; });
Any Ideas? Any help is appreciated.
Currently we are not saving current user's id in forcetk or angular-force.js. But you can get it by parsing oauth_callback response from salesforce. Salesforce's oauth response will include "id" which is the url for the current user and it looks like:
From that "id", you can then get userId.,
To get access to callback response and then to parse id, change the callback controller from:
All Answers
How does your actual/ complete SOQL look like?
I am new to Angular and Node, so I am not sure exactly where to see the exact soql statement.
But, it does work fine if I hard code the id into the code like below.
But my problem is still, how do I grab the current user's id so I can put it in there?
If you are using ngForce, the SalesforceOAuthPlugin class has a methoda called getAuthCredentials() that returns
a dictionary with:
* accessToken
* refreshToken
* clientId
* userId
* orgId
* loginUrl
* instanceUrl
* userAgent
This will get you the userId of the current user from the oAuth dance. Hope this helps.
Regards,
Gaurav
Currently we are not saving current user's id in forcetk or angular-force.js. But you can get it by parsing oauth_callback response from salesforce. Salesforce's oauth response will include "id" which is the url for the current user and it looks like:
From that "id", you can then get userId.,
To get access to callback response and then to parse id, change the callback controller from:
Raja,
That's exactly what I was looking for.
Thank you so much!!
I think this post will really help out others.
Thank you also for that great video that you posted on Angular, it helped greatly.
I'm a fan. =o)