0

I have created VF page that get data from report and bind in VF page. There is also filter functionality implemented for this custom reoport.

Now I have requirement to add Report Filter Logic like we use in standard report filter i.e. (1 AND 2 AND (3 OR 4)). But, I am not able to add it in Apex Class.

    Reports.ReportDescribeResult describe = Reports.ReportManager.describeReport(REPORT_ID);
Reports.ReportMetadata reportMetadata = describe.getReportMetadata();
List<Reports.ReportFilter> lstFilters = new List<Reports.ReportFilter>();

if(String.isNotBlank(strSpread)) {
    String[] spaceSize = strSpread.split(' ');
    if(spaceSize[0].contains('-')) {
        lstFilters.addAll(addRangeFilter('Deal_Quotes__c.Spread__c',spaceSize[0].split('-')[0].trim(), spaceSize[0].split('-')[1].trim()));
    } else if(getEndRangeString(spaceSize[spaceSize.size()-1]) != '') {
        String strrange = getEndRangeString(spaceSize[spaceSize.size()-1]);
        lstFilters.addAll(addRangeFilter('Deal_Quotes__c.Spread__c',
                                        strrange == 'above' ? spaceSize[0].trim() : null,
                                        strrange == 'above' ? null : spaceSize[0].trim()));
    }
}
if(String.isNotBlank(dateRangeFrom)) {
    lstFilters.add(new Reports.ReportFilter('Deal_Quotes__c.Quote_Date__c', 'greaterOrEqual', dateRangeFrom));
}
if(String.isNotBlank(dateRangeTo)) {
    lstFilters.add(new Reports.ReportFilter('Deal_Quotes__c.Quote_Date__c', 'lessOrEqual', dateRangeTo));
}

if(lstFilters.size() > 0) {
    reportMetadata.setReportFilters(lstFilters);
}
return Reports.ReportManager.runReport(REPORT_ID, reportMetadata, true);

Above is my code. Please give me suggestion, where should I add the filter logic?

0

You can use JAVASCRIPT function in your VF page to filter logic i.e. (1 AND 2 AND (3 OR 4)). It's Report Builder JS function of Saleforce.

You can find it in "../analytics-reporting-impl/ReportFilterPanel.js".

Ref: Implement Salesforce filter Criteria Logic

0

Thank you so much codeyinthecloud,

This help me a lot https://developer.salesforce.com/page/Apex_Design_Patterns#Composite

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.