Adding a Button to Run a Report

To add a button to the detail page of the tab associated with the object on which the report is to run:

  1. From Setup, click Create | Objects | YourObject.
  2. Scroll to the Buttons, Links and Actions.
  3. Click New Button or Link.
  4. Complete the Label and Name fields.
  5. Click Detail Page Button.
  6. Select Display in new window from the Behavior drop-down list.
  7. Depending on what your users will do with the report, do one or both of the following:
    • If your users will save the report and send it by email, paste the following code into the text box under the Select Field Type drop-down list:

      /apex/ob1__OutputManager?id={! YourObjectAPI.Id}&class=YourTemplateClass

    • If your users will only view the report in a pop-up window, paste the following code into the text box (under the Select Field Type drop-down list) to create a "View Only" button:

      /apex/ob1__OutputViewer?id={! YourObjectAPI.Id}&class=YourTemplateClass

    • Key:
      YourObjectAPI = the API name of the object on which you are creating the report.
      YourTemplateClass = the name of the template class to which the report belongs.
  8. Click Save.
  9. Add the Detail Page Button you created to the page layout of the object.
  10. If you haven't already done so, add the Output Histories related list to the page layout of the object.

To add a button to the list view of the tab associated with the object on which the report is to run:

  1. From Setup, click Create | Objects | YourObject.
  2. Scroll to the Buttons, Links, and Actions section.
  3. Click New Button or Link.
  4. Complete the Label and Name fields.
  5. Click List Button.
  6. Ensure that the Display Checkboxes (for Multi-Record Selection) checkbox is selected.
  7. Paste the following in the large box beneath the Select Field Type drop-down list:

    var tmp='';
    var arr = {!GETRECORDIDS($ObjectType.YourObjectAPI)};

    for(var i=0;i<arr.length;i++)
    {
    tmp+=arr[i]+',';
    }

    var url = '/apex/ob1__OutputListViewManager?&class=NameofTemplateClass&idset=' + tmp;
    window.open(url, '_blank', 'height=600,location=no,resizable=yes,toolbar=no,status=no,menubar=no,scrollbars=1');

    var arr = {!GETRECORDIDS($ObjectType.YourObjectAPI)};
    for(var i=0;i<arr.length;i++)
    {
    tmp+=arr[i]+',';
    }
    var url = '/apex/ob1__OutputListViewManager?class=NameofTemplateClass&idset=' + tmp;
    self.location=url;

    Where:
    • YourObjectAPI is the API name of the object on which you are creating the report.
    • NameofTemplateClass is the is the name of the template class to which the report relates.
  8. Add the List Button you created to the List View in the Search Layouts section of the object.
  9. If you have not already done so, add the Output Histories related list to the page layout on the object on which the report is to run.