You need to sign in to do that
Don't have an account?

limit dashboard data based on user filter in apex
Hi.
I have created a visual dashboard in salesforce along with a filter at top which displays names of users.
I need the dashboard to be changed when the user is changed in dropdown.
How to achieve this.
CONTROLLER:
<apex:page controller="TopFiveOpenDeals" tabStyle="Opportunity">
<apex:form >
<apex:selectList label="Users" multiselect="false" size="1">
<apex:actionSupport event="onchange" action="{!UpdateSelectedFirstItem}" rerender="page" />
<apex:selectOptions value="{!owner_list}"></apex:selectOptions>
</apex:selectList>
</apex:form>
<apex:panelGrid columns="2" width="20">
<apex:chart height="250" width="450" animate="true" data="{!gaugedata}">
<apex:axis type="Gauge" position="gauge" title="Sum Of TCV"
minimum="0" maximum="1500000" steps="10"/>
<apex:gaugeSeries dataField="data1" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>
<apex:pageBlock title="Top 5 Open Deals" >
<apex:pageBlockSection columns="2" >
<apex:pageBlockTable value="{!opps}" var="opp">
<apex:column value="{!opp.Name}"/>
<apex:column value="{!opp.Total_TCV__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:panelGrid>
</apex:page>
PAGE:
public with sharing class TopFiveOpenDeals {
List<String> nameList{get;set;}
List<selectOption> owner_List{get;set;}
List<User> ownerList{get;set;}
Public TopFiveOpenDeals()
{
ownerList=new List<User>();
ownerList=[Select Id, Name From User where isActive=true AND Profile.name='System Administrator'];
//ownerList=[Select Id, Name From User where isActive=true AND Profile.name='Sales User' AND UserRole.name LIKE '%Sales%'];
nameList=new List<String>();
owner_List=new List<selectOption>();
for(User a:ownerList)
{
nameList.add(a.name);
}
}
public List<SelectOption> getOwner_list()
{
for(String obj:nameList)
{
owner_List.add(new selectOption(obj,obj));
}
return owner_list;
}
public void UpdateSelectedFirstItem()
{
}
public List<Opportunity> getOpps() {
return [ Select Name,Total_TCV__c
from Opportunity
//WHERE Total_TCV__c !=NULL AND (CloseDate= THIS_QUARTER OR CloseDate=NEXT_QUARTER)
WHERE Total_TCV__c !=NULL
ORDER BY Total_TCV__c
DESC LIMIT 5
];
}
}
Thanks,
Laxman
I have created a visual dashboard in salesforce along with a filter at top which displays names of users.
I need the dashboard to be changed when the user is changed in dropdown.
How to achieve this.
CONTROLLER:
<apex:page controller="TopFiveOpenDeals" tabStyle="Opportunity">
<apex:form >
<apex:selectList label="Users" multiselect="false" size="1">
<apex:actionSupport event="onchange" action="{!UpdateSelectedFirstItem}" rerender="page" />
<apex:selectOptions value="{!owner_list}"></apex:selectOptions>
</apex:selectList>
</apex:form>
<apex:panelGrid columns="2" width="20">
<apex:chart height="250" width="450" animate="true" data="{!gaugedata}">
<apex:axis type="Gauge" position="gauge" title="Sum Of TCV"
minimum="0" maximum="1500000" steps="10"/>
<apex:gaugeSeries dataField="data1" donut="50" colorSet="#78c953,#ddd"/>
</apex:chart>
<apex:pageBlock title="Top 5 Open Deals" >
<apex:pageBlockSection columns="2" >
<apex:pageBlockTable value="{!opps}" var="opp">
<apex:column value="{!opp.Name}"/>
<apex:column value="{!opp.Total_TCV__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:panelGrid>
</apex:page>
PAGE:
public with sharing class TopFiveOpenDeals {
List<String> nameList{get;set;}
List<selectOption> owner_List{get;set;}
List<User> ownerList{get;set;}
Public TopFiveOpenDeals()
{
ownerList=new List<User>();
ownerList=[Select Id, Name From User where isActive=true AND Profile.name='System Administrator'];
//ownerList=[Select Id, Name From User where isActive=true AND Profile.name='Sales User' AND UserRole.name LIKE '%Sales%'];
nameList=new List<String>();
owner_List=new List<selectOption>();
for(User a:ownerList)
{
nameList.add(a.name);
}
}
public List<SelectOption> getOwner_list()
{
for(String obj:nameList)
{
owner_List.add(new selectOption(obj,obj));
}
return owner_list;
}
public void UpdateSelectedFirstItem()
{
}
public List<Opportunity> getOpps() {
return [ Select Name,Total_TCV__c
from Opportunity
//WHERE Total_TCV__c !=NULL AND (CloseDate= THIS_QUARTER OR CloseDate=NEXT_QUARTER)
WHERE Total_TCV__c !=NULL
ORDER BY Total_TCV__c
DESC LIMIT 5
];
}
}
Thanks,
Laxman
https://developer.salesforce.com/docs/atlas.en-us.198.0.apexcode.meta/apexcode/apex_methods_system_userinfo.htm#apex_System_UserInfo_getUserId
I need to display all users in the filter and change the dashboard view based user selected.
Thanks,
Laxman
1) If its a standard one , i am afraid you cannot control data being displayed based on a custom filter. You can instead make the dashboard as a dynamic dashboard and try displaying it.
2) If its a custom one, you need to build chart separately using <apex:chart> components and manipulate your queries based on a input selection.
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_charting_overview_simple_example.htm
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_charting_appearance_bar_charts.htm
I have created a whole new cusom dashboard in visual force using apex:chart apex:axis apex:barseries apex;legend and all....
At top I created a picklist which inclides all users available.
now how do i edit my queries to show dashboard data related to particular user.
consider the below method of my controller:
public List<Opportunity> getSalesOpps() {
return [ Select Name,Opportunity.owner.name,Total_TCV__c
from Opportunity
WHERE Total_TCV__c !=NULL AND (CloseDate= THIS_QUARTER OR CloseDate=NEXT_QUARTER)
ORDER BY Total_TCV__c
DESC LIMIT 5
];
}
How should I modify aboveSOQL in method to display data related to user selected above.
Struck here ..would be thankful if sorted out asap
Thanks,
Laxman
I will be selecting only one user from picklist.
On selection, the VF page neds to show only data which he has access(Read/write/Edit).
Example:If User A has User B and user C under him in role hierarchy., If i select user A in picklist, I need to display data acceessibeto B and C along with A's data.
Hope i am clear with explanation
Could you let me know what to modify
I need to query records not just based on ownerId...I should query all records which the user has access to even if he is not a owner