[SalesForce] How to create or clone reports in Apex

I need to display data dynamically from reports, depending on records.

The url hacking way (pv0 and stuff) doesn't work in lightning experience, so I am wondering how I could achieve this in it.

I thought about creating reports from apex, it would be great to use a "template" report, and creatin a new one from it with record-specific parameters, still I couldn't manage to find any good documentation nor code sample to implement such a thing.

The Salesforce Reports and Dashboards API via Apex documentation only provides information on how to retrieve reports data, but not if it is possible to create some using apex.

Is there any way to achieve this ?

Best Answer

Actually managed to clone reports and dashboards using Apex and the Metadata Api provided by Andrew Fawcett on Github.

Just wanted to share it, here's the issue where you can find the code samples used.

Edit: As of API version 34, you can also use the Analytics API for cloning, but you need to do a callout.

Related Topic