+ Start a Discussion

How to edit Reports and Dashboards Programmatically?




I want to customize the Reports and Dashboards through apex code. The API's for Dashboard and Reports are not supporting this. I tried it out with this API link for Dashboards



Is there anyway round where I can get the Reports attributes used in a Dashboard and then able to customize reports accordingly through apex code?




I have access to dashboard object. From this object, I am trying to reach the reports included in the dashboard. The dashboard object has three fields
These are of type DashboardComponentSection.

I was hoping to get to the DashboardComponentSection from Dashboard, and then use the components field to get a list of elements of type Dashboard.
From the DashboardComponent we can get to the name of the report,

However the issue I am running into is that Salesforce does not recognize the field leftSection, middleSection and rightSection in the dashboard object. There appears to be no way to get to DashboardComponentSection from the Dashboard object.
The code below gives compilation error - 

Dashboard d =[Select Id,title,description ,LeftSection,middleSection,rightSection from Dashboard];


You can't SOQL this sort of data; it's covered under the Apex Metadata API. You would have to use a method that can leverage the Metadata API. You can't do this in pure Apex Code due to timing considerations (it's asynchronous), but you could use Visualforce to poll the results, then handle most of the processing in JavaScript or action functions.