I try to create dynamic filtering on report using Report API.User can choose the date THIS_MONTH,LAST_30_DAYS.I set it at setDurationValue asn below :

        system.debug('@@@ getReportwithFilter date'+ dates);
        Reports.standardDateFilter stdDateFilter = reportMD.getStandardDateFilter();
        system.debug('@@@   Reports.standardDateFilter  '+ stdDateFilter );
        stdDateFilter.setDurationValue(dates); //LAST_30_DAYS

        reportOppo = ReportManager.getFilterReportResult(reportId,reportMd);

When I run the code ,I got exception like below :

reports.InvalidFilterException: [The duration NEXT_30_DAYS specified for the standard date filter is invalid.]

I read on Date Format LAST_N_DAYS:n here .But how to define 'N' value in Report API.

  • try this LAST_N_DAYS:30 – Tushar Sharma Jul 26 '16 at 6:59
  • @TusharSharma This works, I thought it only works in SQL .Can you put in Answer so I can accept this as Answer. – unidha Jul 28 '16 at 2:18
  • I have added my answer. – Tushar Sharma Jul 28 '16 at 5:16

Instead of doing NEXT_30_DAYS you should use LAST_N_DAYS:30. This will solve your problem.

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.