3

I'm getting a reportFilter exception up to this it was running fine. And I can not able to find where is the problem exactly. According to the client this problem is introduced after the winter 17 release by salesforce.

When I placed this method inside the try than its giving following in the catch block "reports.InvalidFilterException" nothing more than this I tried different possible methods of Exception class in catch block for getting more details about this but no luck.

Here is my code.

/filter setup for report/

fil = new Reports.ReportFilter('club62__Financial_Summary__c.club62__Date__c','greaterOrEqual',sDate.addDays(-1).year()+'-'+sDate.addDays(-1).month()+'-'+sDate.addDays(-1).day());
                    fil2 = new Reports.ReportFilter('club62__Financial_Summary__c.club62__Date__c','lessThan',sDate2.toStartOfMonth().year()+'-'+sDate2.toStartOfMonth().month()+'-'+sDate2.toStartOfMonth().day());
                    fil3 = new Reports.ReportFilter('club62__Financial_Summary__c.club62__Date__c','lessOrEqual',sDate.addDays(-1).year()+'-'+sDate.addDays(-1).month()+'-'+sDate.addDays(-1).day());
                    fil4 = new Reports.ReportFilter('club62__Financial_Summary__c.club62__Yearly_Summary__c','equals','false');
                    fil5 = new Reports.ReportFilter('club62__Financial_Summary__c.club62__Yearly_Summary__c','equals','true');
                    fil6 = new Reports.ReportFilter('club62__Financial_Account__c.club62__Balance_Sheet_Type__c','notEqual','');
                    booleanFilter = '((1 AND 2 AND 4) OR (3 AND 5 AND 6))';
                    filList.add(fil);
                    filList.add(fil2);
                    filList.add(fil3);
                    filList.add(fil4);
                    filList.add(fil5);
                    filList.add(fil6);

                    if(filter1!= null && filter1!=''){
                        fil7 = new Reports.ReportFilter('CUST_ID','equals',filter1);
                        filList.add(fil7);
                        booleanFilter += ' AND '+filList.size();

                    }
                    if(filter2!=null && filter2!=''){
                        Reports.ReportFilter filGLS = new Reports.ReportFilter('club62__Financial_Account__c.club62__Account_Number__c','greaterOrEqual',filter2);
                        filList.add(filGLS);
                        booleanFilter += ' AND '+filList.size();
                    }
                    if(filter3!=null && filter3!= ''){
                        Reports.ReportFilter filGLS = new Reports.ReportFilter('club62__Financial_Account__c.club62__Account_Number__c','lessOrEqual',filter3);
                        filList.add(filGLS);
                        booleanFilter += ' AND '+filList.size();
                    }

                    if(locationFilter!=null && locationFilter!=''){
                        filList.add(new Reports.ReportFilter('club62__Financial_Summary__c.club62__Financial_Account_Location__c','equals',locationFilter.left(15)));
                        booleanFilter += ' AND '+filList.size();
                    }
                    runThisRun = true;
                }               

                Reports.ReportMetadata meta = new Reports.ReportMetadata();                   
                meta.setReportFilters(filList);        


/*run report*/

meta.setHasRecordCount(true);
                        meta.setAggregates(new List<String>{'s!club62__Financial_Summary__c.club62__Actual__c','s!club62__Financial_Summary__c.club62__Debit__c','s!club62__Financial_Summary__c.club62__Credit__c','RowCount'});
                        Reports.GroupingInfo gi = new Reports.GroupingInfo();
                        gi.setName('CUST_ID');
                        gi.setsortOrder(Reports.ColumnSortOrder.ASCENDING);
                        gi.setDateGranularity(Reports.DateGranularity.NONE);

                        List<Reports.GroupingInfo> gil = new List<Reports.groupinginfo>();
                        gil.add(gi);

                        meta.setGroupingsDown(gil);                    
                        meta.setDetailColumns(new List<String>{'club62__Financial_Summary__c.club62__Actual__c','club62__Financial_Account__c.club62__Account_Number__c','club62__Financial_Summary__c.club62__Debit__c','club62__Financial_Summary__c.club62__Credit__c'});                                            
                        try
                        {                              
                            Reports.ReportManager.runAsyncReport(reportId,meta,true);                              
                        }
                        catch(Exception e)
                        {                                                                        
                            System.debug(e.getTypeName()+'Exception');                                                             
                            return false;
                        }
4
  • Just to isolate the issue, do you get the same error when you try to change the constructor signature from reportId,meta,includedetails to reportId, includedetails? – Rao Nov 21 '16 at 18:52
  • One of the things I noticed was the column names are case sensitive eg: account.name is invalid filter, the column param has to be ACCOUNT.NAME. So I would recommend to use LIST<String> detailsColumnsAPINames = meta.getDetailColumns(); and copy paste the exact column name as param for ReportFilter method to see if this error goes away. – Rao Nov 21 '16 at 19:19
  • 1)Yes Rao when I skip the filter(meta)param in the constructor report is running fine and any filter is not getting apply. – user3446467 Nov 22 '16 at 6:56
  • I Just confirmed all the columns in reportFilter with the api name of the objects manually It seems to be fine. When prints the column name by meta.getDetailColumns() than it is listing all the column names same as what I am setting in the code from below line meta.setDetailColumns (...) – user3446467 Nov 22 '16 at 7:03
1

I am not sure but this problem has introduced after winter17 release and before to this release ReportMetadata class was allowing to set the reportScope as null but now I think its mandatory to set the reportScope by using setScope() of ReportMetadata class.

just added the following line to my code and its worked

meta.setScope('organization');

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.