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
R R MR R M 

How to Show Dashboards on Visualforce page Based on Current Loggedin User

HI Folks. 
Please do Help.
How to Show Dashboards on Visualforce page Based on Current Loggedin User

Thanks in Advance
NagendraNagendra (Salesforce Developers) 
Hi,

Running a dashboard in present user context.

Then you can do this by setting it on the dashboard (Current logged in user). And the user in above code is UserInfo.getUserId() 
 
try this : 
List<Dashboard> dbs=[select id, RunningUserId, Title from Dashboard ];
dbs[0].RunningUserId = UserInfo.getUserId() ;
Update dbs[0];
But "RunningUserId" is not writable. If there is specific user selected on the dashboard and you want to change it via apex then it is not possible. But if you want that dashboard should run always in present logged in user then you can do this by :
 
Go To Dashboard > Edit > View Dashboard As > Select "Run as Logged in User" > Save.

Hope this helps.

Kindly mark this as solved if the information was helpful so that it gets removed from the unanswered queue which results in helping others who are encountering a similar issue.

Thanks,
Nagendra
R R MR R M
HI Nagendra, 

Can you please help with the code.