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
davidjbbdavidjbb 

SQLof the Current User

Hello Community,

 

I want to retrieve the records of the custom/standard object of the current user. 

 

In addition, what if for example I want to grab the records of the current user and their profiled organization. I.E Bob's profile has set Organization to "Rakio". I want to grab records that belong to Bob who is the current user logged in, and "Rakio"

 

Thank you,
David 

Best Answer chosen by Admin (Salesforce Developers) 
Jia HuJia Hu
Id aid = Userinfo.getUserId();
account ac = [Select Id, Name from Account Where CreatedById = : aid limit 1];
System.debug(' ---- ' + ac );

All Answers

Jia HuJia Hu
use Where CreatedById or OwnerId = your current user Id in the SOQL query
Jia HuJia Hu
Id aid = Userinfo.getUserId();
account ac = [Select Id, Name from Account Where CreatedById = : aid limit 1];
System.debug(' ---- ' + ac );
This was selected as the best answer
craigmhcraigmh

Closer to this:

 

Id aid = Userinfo.getUserId();
List<Account> ac = [Select Id, Name From Account Where CreatedById = : aid Limit 10000];