Build Apps Like a Pro

Achieve App Builder Certification Become an App Builder Pro

Salesforce Pending Approvals Report

If you have one or more approval processes, you may find a requirement to be able to report on records that are pending approval. As well as knowing the records, we probably will want to know who the record has been assigned to for approval, so we can follow up or reassign if the person is not available. If you have a look at the standard reports, you won’t find one that lists pending approvals. Next stop is usually Google, and if you do search for answers on this topic, you will find many people before asking the same question. How can we report on pending approvals?

After reviewing the search results to your query, you will find your way to a Salesforce help link: Fields Available for Approval History Reports

This promises to solve the requirement, with the description of :

If you create a custom report type with Process Instance as the primary object and Process Instance Node as the related object, you can create approval history reports with various combinations of fields that enable you to view a detailed history of executed and in-progress approval processes and their individual steps..

So, next step custom report types. After creating a custom report type, we return to the report builder, and eagerly run our report. He are the results after running the report, where I have filtered the status to only show Pending approval requests.

salesforce-pending-approval-report

This looks promising. We can see the 5 pending approval requests listed, across the 2 objects, Opportunity and Work Order. We have a link to the record, we can see the status and when it was submitted. One thing that is missing, is the user that the approval request is currently assigned to for approval. Back to the report builder, and after going through all of the available fields, unfortunately it is not available. So, we can list pending approval requests, but not with the user it is pending with. This maybe satisfactory, as we can drill down into each record and check the approver assignment, but in cases where we really need to see the pending approvers in the report, we need another solution.

After considering our options, we may decide that we will put the time into developing a Visualforce report, as we will be able to design it to include the fields we want, including the approver name. Fortunately, creating a simple list report, is not difficult. It just needs a query against the appropriate objects, and we are able to retrieve the approver name. Here is what our simple report looks like:

Pending Approvals Visualforce Report

salesforce-pending-approvals-report-vf

To get this to work, you will need to create the APEX class first, then create the Visualforce page.

APEX Code:

[crayon-6114a5caae79d916399959/]

Visualforce Page

[crayon-6114a5caae7a2777808539/]

[crayon-6114a5caae7a4103181448/]

What Certification are you studying for now?

Focus on Force currently provides practice exams and study guides for sixteen certifications

Comments

  1. Cloud 11

    I can’t find the code for Apex Class and Visualforce Page, it appears to me like that :

    To get this to work, you will need to create the APEX class first, then create the Visualforce page.

    APEX Code:

    Visualforce Page

        1. Ian Focus Team

          Hi Liangyu Yi, thanks for letting us know. The article is currently being reviewed and should be fixed very soon.

  2. Matthew Hammel

    I’m a complete noob. I created the apex class and visualforce page. How do I generate the visualforce report?

    1. Ian Focus Team

      Hi Matthew, thanks for the enquiry. The quickest way to open the Visualforce page is to access it via its own URL. You can go to “Setup > Visualforce Pages” and then click on the preview button (arrow icon) for your Visualforce page. Or, you can create a Visualforce Tab in “Setup > Tabs” and then access the Visualforce page from App Launcher or your navigation menu. More options can be found here: https://trailhead.salesforce.com/content/learn/modules/lex_dev_visualforce/lex_dev_visualforce_intro

  3. ryansherry

    @istest
    private class getWrapData_test {

    @isTest(SeeAllData=true) static void testMethodOne() {
    pagereference pageRef = page.ApprovalHistoryReport;
    test.setCurrentPage(pageRef);

    getWrapData controller = new getWrapData();

    controller.getWrapList();

    }

    }

    1. ryansherry

      I wrote this fast but it tests this controller quickly. The see all data part assumes you have these records in the environment your deploying in

  4. Julie S (anyrelm, LLC)

    Hi – This has been super helpful and something we are implementing for a client. I am wondering if you have sample code for a test class for this that you could post. Having some issues with the data structure for approvals and thought might be easiest to start with you before we dive deeper into the Process data model to create a test class. Thank you for any guidance!

    1. Martin Gessner Focus Team Post author

      Hi Julie,

      That’s great that you found it useful. Sorry we don’t have a test class created for this, but feel free to post it back here if you develop!

      Martin