function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Barton LedfordBarton Ledford 

Has anyone updated report filters through the metadata api?

We can get updateMetadata to work with reports.


We cannot update an existing report via the metadata api.  upsertMetadata will insert a new report if we change any character of the report fullname, but won't do an update if the fullname remains the same (Error: duplicate values on record with id <unknown>).  If I try updateMetadata, I get "In field: fullName - no Report named NSPC__Client_App_Reports/Top_Goals_for_Top_Salespeople found".  Any help is much appreciated.

HTTP h = new HTTP();
HTTPRequest req = new HTTPRequest();
req.setMethod('POST');
req.setHeader('Content-Type', 'text/xml');
req.setHeader('SOAPAction', 'upsertMetadata');
String b = '<?xml version="1.0" encoding="UTF-8"?>';
b += '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">';
b += '<soapenv:Header>';
b += '<ns1:SessionHeader soapenv:mustUnderstand="1" xmlns:ns1="http://soap.sforce.com/2006/04/metadata">';
b += '<ns1:sessionId>' + UserInfo.getSessionId() + '</ns1:sessionId>';
b += '</ns1:SessionHeader>';
b += '</soapenv:Header>';
b += '<soapenv:Body>';
b += '<upsertMetadata xmlns="http://soap.sforce.com/2006/04/metadata">';
b += '<metadata xsi:type="ns2:Report" xmlns:ns2="http://soap.sforce.com/2006/04/metadata">';
b += '<fullName>NSPC__Client_App_Reports/Top_Goals_for_Top_Salespeople</fullName>';
b += '<columns>';
b += '<field>CUST_ID</field>';
b += '</columns>';
b += '<filter>';
b += '<criteriaItems>';
b += '<column>NSPC__Event__c.NSPC__Name__c</column>';
b += '<operator>equals</operator>';
b += '<value>View</value>';
b += '</criteriaItems>';
b += '<criteriaItems>';
b += '<column>CUST_OWNER_NAME</column>';
b += '<operator>equals</operator>';
b += '<value>John Doe,Barton Ledford</value>';
b += '</criteriaItems>';
b += '</filter>';
b += '<format>Summary</format>';
b += '<groupingsDown>';
b += '<dateGranularity>Day</dateGranularity>';
b += '<field>NSPC__Event__c.NSPC__Name__c</field>';
b += '<sortOrder>Asc</sortOrder>';
b += '</groupingsDown>';
b += '<name>Top Goals for Top Salespeople</name>';
b += '<params>';
b += '<name>co</name>';
b += '<value>1</value>';
b += '</params>';
b += '<reportType>CustomEntity$NSPC__Event__c</reportType>';
b += '<scope>organization</scope>';
b += '<showDetails>false</showDetails>';
b += '<timeFrameFilter>';
b += '<dateColumn>NSPC__FolioEvent__c.NSPC__eventTime__c</dateColumn>';
b += '<interval>INTERVAL_CUSTOM</interval>';
b += '</timeFrameFilter>';
b += '</metadata>';
b += '</upsertMetadata>';
b += '</soapenv:Body>';
b += '</soapenv:Envelope>';
req.setBody(b);
req.setCompressed(false);
req.setEndpoint(URL.getSalesforceBaseUrl().toExternalForm() + '/services/Soap/m/31.0');
HTTPResponse resp = h.send(req);
System.debug(resp.getBody());
 
ShashankShashank (Salesforce Developers) 
Though we cannot update reports, we can Filter reports on the fly to get filtered data using the analytics API. The source report will not be modified though: http://www.salesforce.com/us/developer/docs/api_analytics/Content/sforce_analytics_rest_api_filter_reportdata.htm