You need to sign in to do that
Don't have an account?
James Hayes
Any help would be appreciated. I am fairly new at this. Thanks
How do I reference My Opportunities
Hey All, I am trying to get a visualforce page to reference the "My Opportunities" view in salesforce. I am doing a list view on the left and a page view of the opportunity on the right. But, I only want it to view the opportunities that are associated to the owner opening the visualforce page. Here is my current code. <apex:page standardController="Opportunity" recordSetVar="ops" sidebar="false"> <apex:form > <apex:pageBlock > <apex:pageBlockSection > <apex:pageBlock Title="List of Opportunities"> <apex:pageblockTable value="{!ops}" var="o"> <apex:column > <apex:commandLink value="{!o.Name}" reRender="refresharea"> <apex:param name="OpportunityID" value="{!o.ID}"/> <apex:param name="OpportunityName" value="{!o.Name}" /> </apex:commandLink> </apex:column> <apex:column value="{!o.Amount}"/> <apex:inlineEditSupport /> <apex:column value="{!o.StageName}"/> <apex:column value="{!o.Closedate}"/> </apex:pageBlockTable> </apex:PageBlock> <apex:pageBlock title="{!$CurrentPage.parameters.OpportunityName}" id="refresharea"> <apex:detail subject="{!$CurrentPage.parameters.opportunityID}" relatedList="false"/> </apex:pageBlock> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
Any help would be appreciated. I am fairly new at this. Thanks
Apex controller
VF Page
All Answers
There is an attribute 'rendered' in apex:column.You can check whether opportunity owner is same as the logged in user in this attribute. Column will be rendered only if the value of 'rendered' attribute is true.(By default it is true).
Give condition as follows.
rendered="{!CASESAFEID(o.ownerid) == $User.Id}"
Return value of o.ownerid in visualforce page is 15 digit and $User.Id is 18 digit. That is why CASESAFEID() is used for converting the 15 digit ID to 18 digit and make them comparable.
See the Modified code
<apex:pageblockTable value="{!ops}" var="o">
<apex:column rendered="{!CASESAFEID(o.ownerid) == $User.Id}">
<apex:commandLink value="{!o.Name}" reRender="refresharea">
<apex:param name="OpportunityID" value="{!o.ID}"/>
<apex:param name="OpportunityName" value="{!o.Name}" />
</apex:commandLink>
</apex:column>
<apex:column value="{!o.Amount}" rendered="{!CASESAFEID(o.ownerid) == $User.Id}"/>
<apex:inlineEditSupport />
<apex:column value="{!o.StageName}" rendered="{!CASESAFEID(o.ownerid) == $User.Id}"/>
<apex:column value="{!o.Closedate}" rendered="{!CASESAFEID(o.ownerid) == $User.Id}"/>
</apex:pageBlockTable>
</apex:PageBlock>
It will return opportunities of logged in user only.
The code looks like it is working with one exception. It does not show the opportunity name with the command link. It shows the following without the opportunity name.
Here is the code.
Can you assist? Appreciate it!
Replace this line in your code with the below line.
<apex:column rendered="{!CASESAFEID(o.ownerid) == $User.Id}">
You have missed '!'. That is the reson the name of opportunity is not displaying in your view.
Running into a new problem. It looks like the code is only pulling My Opportunities if I actually click on a my opportunities report prior to previewing the code. If I select another report, then it just comes back blank. Any thoughts on this? Here is a snapshot of the report I click in the opportunity object.
If I select another report and then preview the VF, nothing shows up.
This page does not specify a filter in the request, so the page is displayed with the last used filter. For information on using filters with list controllers, see https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_list_views.htm
You can simply achieve this functionality by adding a custom controller as an extension and fetch required opportunities in its constructor.
If we are using standard controller and recordsetvar for fetching data, it will display records only in the current view. For more detail see https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_list_views.htm
Apex controller
VF Page
Appreciate it. This worked, I have one additional question though, would there be a way to have it only display curren open opportunities that belong to the user viewing it?
Current Open opportunities means the opportunities with status not equal to closed. Right?
If Right, modify the query as follows.
SELECT id,name,amount,stagename,closedate,ownerid FROM Opportunity WHERE owner.id =: userinfo.getuserid() AND isClosed=false