+ Start a Discussion
vleandrovleandro 

How to pass Owner to a report via a Visualforce page

This relates to a custom object, but could easily be any standard object in Salesforce.

 

Basically I'm wanting to run a report that shows all records owned by the person logged into Salesforce.

 

In this instance we have an object called Incidents.  

 

I have a report where I defined the filter as:

 

Incident: Owner Name equals ""
 
Before I even started on the VF page, I first created a custom link that I could add to my standard page layout and verify that the person who is logged into Salesforce would have their name passed to the report.  My custom link URL is this:
 
/00Oi0000004ZLjh?pv0={!User.Name}
 
Works great.  If I log in as myself and click on the link, I see all Incidents that I own.  If I log in as someone else, then he sees all the incidents that he owns.
 
So far...so good!
 
Now what I want is a Visualforce Page that would host a number of these Report "URLs" that a logged in user could select from.
 
<apex:page standardController="Incident__c">

<p>
   <a href = "/00Oi0000004ZLjh?pv0={!User.Name}" target="_blank">Incidents Assigned to Me</a>
</p>

</apex:page>

 When I try and save the page, I get:

 

Error: Unknown property 'BMCServiceDesk__Incident__cStandardController.User'

 

I also tried this:

 

<apex:page standardController="BMCServiceDesk__Incident__c">

<p>
   <a href = "/00Oi0000004ZLjh?pv0={$User.Name}" target="_blank">My Incidents</a>
</p>

</apex:page>

 

I'm able to save the page; howerver when I click on the URL link to the report, it looks like this and I'm not getting any data returned.

 

https://na15.salesforce.com/00Oi0000004ZLjh?pv0={$User.Name}

 

Is there another "session" variable equivilent to Owner Name that I could use in this instance?

 

Thank you!

Virginia

 

 
Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox
Formula expressions always start with {! and end with }. This is why {$User.Name} doesn't work. Normal variables start with a name, so {!User.Name} tries to resolve to a public or variable in any controller or extension named "user", which you have neither of, and so it doesn't resolve either.

Instead, you need to use the global variable (which starts with $). The correct answer, then, is that you need both the ! and $: {!$User.FirstName}. Note that Name isn't valid; you would have to use FirstName and LastName.

All Answers

sfdcfoxsfdcfox
Formula expressions always start with {! and end with }. This is why {$User.Name} doesn't work. Normal variables start with a name, so {!User.Name} tries to resolve to a public or variable in any controller or extension named "user", which you have neither of, and so it doesn't resolve either.

Instead, you need to use the global variable (which starts with $). The correct answer, then, is that you need both the ! and $: {!$User.FirstName}. Note that Name isn't valid; you would have to use FirstName and LastName.
This was selected as the best answer
vleandrovleandro

Thank you!  I finally arrived at the solution you recommended; but had to wonder if I was missing something.

 

I appreaciate the help and clarification!

 

V