0

I am looking to create a new report programmatically and set its audit fields (CreatedBy, CreatedDate, LastModifiedBy, LastModifiedDate). I followed this REST API Documentation to create a report successfully, but can't seem to figure out a way to set the audit fields in the input JSON denoted by requestBodyJSON below...?

Unfortunately, DML is not allowed on Report object and the audit fields can only be set at the time of creation, so wondering if below can be tweaked to allow audit fields or perhaps there are other ways of accomplishing below? Any ideas?

REST API method to create a new report:

String requestBodyJSON = '{"reportMetadata":{"aggregates":["RowCount"],"chart":null,"crossFilters":[],"currency":null,"description": null,"userOrHierarchyFilterId": null,"supportsRoleHierarchy": false,"showGrandTotal": true,"showSubtotals": true,"detailColumns":["FK_NAME"],"developerName":"TEST_REPORT_001","division":null,"folderId":"00D0u0000008rwKBCQ","groupingsAcross":[],"groupingsDown":[],"hasDetailRows":true,"hasRecordCount":true,"historicalSnapshotDates":[],"name":"TEST REPORT 001","reportBooleanFilter":null,"reportFilters":[],"reportFormat":"TABULAR","reportType":{"label":"Cases","type":"CaseList"},"scope":"organization","sortBy":[],"standardDateFilter":null,"standardFilters":null}}';
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v39.0/analytics/reports/');
req.setBody(requestBodyJSON);
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
req.setHeader('Content-Type', 'application/json');
req.setMethod('POST');
HttpResponse res = h.send(req);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.