Use jQuery to check if a report returned rows in Apex

In order to conditionally hide/show a button, I needed to know whether a particular report on a page returned any rows.

This can easily be done with a line of jQuery, which differs between classic and interactive reports:

  1. Make sure to give your report a static ID. In this example it is emp.
  2. Classic Report: ┬áIf data is returned there will be a div with an id that prepends ‘report_’ to the report static id. Check the length of that div to find out if it exists. If it doesn’t, the length will be zero, meaning no rows were returned.
  3. Interactive Report:
    1. Here, if the length comes back as one, the report returned no rows.

Thanks to @rimblas for a correction.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.