1

I am looking to update the report type of an existing report via REST API. First I get the report metadata via a GET/describe, then I string-replace just the report type (assuming there is just one generic report type independent column in the report), then POST an UPDATE via PATCH method.

GET/describe returns this JSON:

{"reportMetadata":{"aggregates":["RowCount"],"chart":null,"crossFilters":[],"currency":null,"description":null,"detailColumns":["FK_NAME"],"developerName":"TEST_REPORT_002","division":null,"folderId":"00D0u0000008rwKBCQ","groupingsAcross":[],"groupingsDown":[],"hasDetailRows":true,"hasRecordCount":true,"historicalSnapshotDates":[],"id":"00O0u000000df4eEAA","name":"TEST REPORT 002","reportBooleanFilter":null,"reportFilters":[],"reportFormat":"TABULAR","reportType":{"label":"Cases Custom Object with Parents","type":"CustomEntity$Case__c@Case__c.ParentLookup__c"},"scope":"organization","showGrandTotal":true,"showSubtotals":true,"sortBy":[],"standardDateFilter":{"column":"FK_ParentLookup__c.Some_Date__c","durationValue":"CUSTOM","endDate":null,"startDate":null},"standardFilters":null,"supportsRoleHierarchy":false,"userOrHierarchyFilterId":null}}

Then replace the standard report type text in JSON from one that reference a custom case object:

"reportType":{"label":"Cases Custom Object with Deals","type":"CustomEntity$Case__c@Case__c.ParentLookup__c"}

to that of standard Case object:

"reportType":{"label":"Cases Standard Object with Parents","type":"CaseList@Case.ParentLookup__c"}

Replaced JSON, ready to be POSTed:

{"reportMetadata":{"aggregates":["RowCount"],"chart":null,"crossFilters":[],"currency":null,"description": null,"userOrHierarchyFilterId": null,"supportsRoleHierarchy": false,"showGrandTotal": true,"showSubtotals": true,"detailColumns":["FK_NAME"],"developerName":"TEST_REPORT_002","division":null,"folderId":"00D0u0000008rwKBCQ","groupingsAcross":[],"groupingsDown":[],"hasDetailRows":true,"hasRecordCount":true,"historicalSnapshotDates":[],"name":"TEST REPORT 002","id":"00O0u000000df4eEAA","reportBooleanFilter":null,"reportFilters":[],"reportFormat":"TABULAR","reportType":{"label":"Cases Standard Object with Parents","type":"CaseList@Case.ParentLookup__c"},"scope":"organization","sortBy":[],"standardDateFilter":{"column":"FK_ParentLookup__c.Some_Date__c","durationValue":"CUSTOM","endDate":null,"startDate":null},"standardFilters":null}}

POST Method:

Id reportId = '00O0u000000df4eEAA';
Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/data/v39.0/analytics/reports/' + reportId + '?_HttpMethod=PATCH');
req.setBody(replacedBodyJSON); //See above for the JSON string
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());
req.setHeader('Content-Type', 'application/json');
req.setMethod('POST');
HttpResponse res = h.send(req);

Notice that the original JSON string and the one posted are almost identical, barring the change to report type. When I post this update, I get below error:

CALLOUT_RESPONSE [245]|System.HttpResponse[Status=Bad Request, StatusCode=400]
USER_DEBUG [247]|ERROR|----> RESPONSE = [{"errorCode":"BAD_REQUEST","message":"value \"\" is not one of the picklist choices."}]

I am struggling to tell the reason for this error. There is no picklist field in the JSON being posted at all. Which picklist is it referring to exactly? How to fix it? Or, what can I try?

I certainly got this approach to work on standard report types referencing custom objects, but NOT with standard report types referencing standard Case object.

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.