6

It is possible to read reports with Apex with SOQL

SELECT Id, Name, DeveloperName from Report

However it is NOT possible to update such records. I decided to use jsforce in this case and Metadata API to proceed with my changes. I was able to change Name by retrieving the report with conn.metadata.read('Report', [fullNames]) then update the key name and pass it to conn.metadata.update('Report', metadata).

But when I decide to change DeveloperName I know that fullName is composed from folder.DeveloperName/report.DeveloperName so if I try to read for the report with the new DeveloperName it returns an empty list as the name do not exist.

Is it generally possible to change DeveloperName with APEX or using jsforce? If so, how? I DO NOT need any source code. A short description of the approach is totally sufficient!

1 Answer 1

8

You can use the Salesforce Reports and Dashboards REST API from within Apex. Given you know the Report ID from the query, you just need to send a PATCH method to the API. See Save Changes to Reports. Of course, if you're in Lightning, this might be restricted, so you need to grab a Session ID that supports API access, as outlined in Making API Calls from Apex.

1
  • Our "trick" for Lightning is always the same: a) create a Visualforce Page in addition to the Lightning Compo. b) put the VF into an IFRAME inside the LC c) wire-up a window.sendMessage() communication between LC and VF d) do everything which requires a "full power Session ID" in VF. e) send the results back to the LC via sendMessage() --- Ugly that this is necessary, but serves the purpose. And it works fine with the API you mentioned. Thanks @sfdcfox !!
    – Uwe Heim
    Commented Dec 17, 2021 at 9:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .