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
PanchoPancho 

Android Native App with SOQL query that references current user

Hi Everyone,

I know its so easy in APEX code, but I am writing a native Android Java app, and I want to do a query that returns a custom object (Retail_Stores) where the current user is the owner of that object.  I am not sure how to reference the current user or get his id.  Any help is greatly appreciated.  Here is what my current query looks like.

String sfRequest = "SELECT Name, Id, Lat__c, Long__c, Address_1__c, City__c, State__c, Phone__c, Retailer_Store_Type__c, Field_Team_Tier__c FROM Retail_Store__c  WHERE (Retail_Store__c.Owner= :UserInfo.getUserId())  LIMIT "+maxNumStores;

 

Thanks for your consideration and help.

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

If you're using the Mobile SDK, then the ClientInfo class has the user's userId, you can get to that from the RestClient instance. e.g. restClient.getClientInfo().userId you can then put this userId as a literal value into your query, e.g. String soql = "select id,name from retail_store__c where ownerId='" + userId + "'";

All Answers

SuperfellSuperfell

If you're using the Mobile SDK, then the ClientInfo class has the user's userId, you can get to that from the RestClient instance. e.g. restClient.getClientInfo().userId you can then put this userId as a literal value into your query, e.g. String soql = "select id,name from retail_store__c where ownerId='" + userId + "'";

This was selected as the best answer
PanchoPancho
Thanks so much Simon!