Thanks anyone for listening. I have added a section to our User page layout consisting of 14 custom fields that are used to track sales performance (most use the DLRS app to roll up data from opportunities). I want to create a Visualforce tab that users can click on to easily view this data. I have zero experience with Apex but went about it two ways: (1) using the $User fields which is perfect as it retrieves the logged in user details but doesn't follow the field format (i.e. % values displayed as decimal) (2) using StandardController="User". This looks much nicer from a formatting standpoint but I can't figure out how to get it to display logged in user data without manually updating the URL.
Assuming I have to write an apex class to query this data, would someone be able to help me get started? I really want to learn and feel like if I knew how to start I could build off of that for future development. Thanks

Sample (1)

<apex:pageBlockSection title="Sales Performance" columns="4">
        <apex:pageBlockSectionItem >
         <p> Sales Target </p>
         <p> Open Pipeline </p>
         <p> Won Opps Year to Date </p>
         <p> Lost Opps Year to Date </p>
         <p> Shortfall </p>
         <p> Nbr of Closed Opps </p>
         <p> Nbr of Open Opps </p>
       <apex:pageBlockSectionItem >
         <p> ${!$User.Sales_Target__c} </p>
         <p> ${!$User.Open_Pipeline__c} </p>
         <p> ${!$User.WonOpps_CY__c} </p>
         <p> ${!$User.LostOpps_CY__c} </p>
         <p> ${!$User.Shortfall__c} </p>
         <p> {!$User.Nbr_Closed_Opps__c} </p>
         <p> {!$User.Nbr_Open_Opps__c} </p> 

Sample (2)

<apex:page standardController="User">
 <apex:pageBlock title="Sales Target Tracking">
   <apex:pageBlockSection title="Sales Performance">
     <apex:pageBlockSectionItem > 
       <apex:outputField value="{! User.Sales_Target__c }"/>
       <apex:outputField value="{! User.Win_Rate__c }"/>
       <apex:outputField value="{! User.Open_Pipeline__c }"/>
       <apex:outputField value="{! User.Loss_Rate__c }"/>
       <apex:outputField value="{! User.WonOpps_CY__c }"/>

1 Answer 1


Typically, in order to avoid writing a controller, you'd add a button or link on the user detail page. If you want it as at tab, you can, but you'll have to do a bit of trickery. The following code should work:

<apex:page standardController="User" 
    action="{!IF(ISBLANK($CurrentPage.parameters.id), URLFOR($Page.theSamePage, 
        $User.Id, [id=$User.Id]), null)}">

This basically says "If the current page's Id parameter is blank, redirect to the same page but with the id parameter set to the current user Id." Make sure to replace theSamePage with the page's name.

  • @sfdcfox-thanks for the quick response! I tried this but now when I click on the tab, above the title, the action statement appears (example below) action="c.cs47.visual.force.com/apex/…">
    – toddk
    Dec 21, 2017 at 6:07
  • I tried to create a link as well on the homepage but received an error message indicating that id value is not valid for user controller. Take any suggestions you may have and thanks again
    – toddk
    Dec 21, 2017 at 6:09
  • @toddk The code above works in my org verbatim (with the name of the page changed). Make sure you're following it precisely.
    – sfdcfox
    Dec 21, 2017 at 6:12
  • <apex:page standardController="User"> action="{!IF(ISBLANK($CurrentPage.parameters.id), URLFOR($Page.Sales_Performance_2, $User.Id, [id=$User.Id]), null)}"> <apex:pageBlock title="Sales Target Tracking">
    – toddk
    Dec 21, 2017 at 6:27
  • @toddk <apex:page standardController="User" action="{!IF(ISBLANK($CurrentPage.parameters.id), URLFOR($Page.Sales_Performance_2, $User.Id, [id=$User.Id]), null)}"> You had a stray > in there.
    – sfdcfox
    Dec 21, 2017 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.