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
Walter@AdicioWalter@Adicio 

How do I add the Id for current user {$User.id} into a SOQL statement?

The page will not be loaded from a link/button on the User page, so I cant add a User Id parameter to the link/button, i.e.

 


/apex/myPage?id={!User.id} where t.User__r.id = :ApexPages.currentPage().getParameters().get('Id')

 

I would like to be able to place the link anywhere but have the page only display the record for the current user viewing the page.

 

 

My Class:

 

 

public class tobExtension { private final Time_Off_Info__c tob; public tobExtension(ApexPages.StandardController stdController) { this.tob = (Time_Off_Info__c)stdController.getRecord(); } List<Time_Off_Info__c> tobRecords; public List<Time_Off_Info__c> getTobRecords() { if( tobrecords == null) tobrecords = [Select t.User__c, t.Total_Time_Off_Available_Hours__c, t.Total_Pending_PTO_Requests__c, t.Total_PTO_Hours_Accrued_2__c, t.Total_PTO_Available__c, t.Total_PTO_Accrued__c, t.Pending_PTO_Balance_Hours__c, t.Payroll_System__c, t.PTO_Balance_Hours__c, t.PTO_Balance_Days__c, t.PTO_Available_current_as_of__c, t.Name, t.Id, t.Employee_Number__c From Time_Off_Info__c t where t.User__r.id = '$User.id']; return tobrecords; } }

 

My Page:

 

 

<apex:page standardcontroller="Time_Off_Info__c" extensions="tobExtension"> <apex:sectionHeader title="My Time Off Balance"/> <apex:pageBlock title="Current User: {!$User.Username}"> <apex:pageBlockTable value="{!tobrecords}" var="tob"> <apex:column value="{!tob.Employee_Number__c}" /> <apex:column value="{!tob.User__c}"/> <apex:column value="{!tob.Total_PTO_Accrued__c}"/> <apex:column value="{!tob.PTO_Available_current_as_of__c}"/> <apex:column value="{!tob.Total_Pending_PTO_Requests__c}"/> <apex:column value="{!tob.Total_PTO_Available__c}"/> </apex:pageBlockTable> </apex:pageBlock> </apex:page>

 

 Thank you.

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
WhyserWhyser

Can you use the UserInfo Object?

 

where t.User__r.id :UserInfo.getUserId()

 

All Answers

WhyserWhyser

Can you use the UserInfo Object?

 

where t.User__r.id :UserInfo.getUserId()

 

This was selected as the best answer
Walter@AdicioWalter@Adicio

Yes this worked, thank you very much.

 

 

where t.User__c = :UserInfo.getUserId()