function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JRTConsultJRTConsult 

How to Display "Approval History" as the only Related List on a Visualforce Page

I have build a "read-only" version the data from a custom object using visualforce. I can layout all the fields on the page, but I don't know how to add just the "Approval History" related list section to the page. It seems like there should be some simple syntax to show or hid related list sections associated with that object.
 
Thank you in advance for your response.
Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae
This is the tag:

Code:
 <apex:relatedList list="ProcessSteps" ></apex:relatedList>

 
plus whatever you need to add for formatting

All Answers

MPIMPI
I may not have understood exactly what you're looking to do, but I believe you can accomplish that by simply using an tag.



Note: Name of the list should be available in the setup page for your custom object.

You can find the full documentation for that tag in the appendix of:
http://www.salesforce.com/us/developer/docs/pages/index.htm

Hope that's what you were looking to do.
JRTConsultJRTConsult
What was the type of tag? I didn't see the tag type in your response.
 
Thanks.
JimRaeJimRae
This is the tag:

Code:
 <apex:relatedList list="ProcessSteps" ></apex:relatedList>

 
plus whatever you need to add for formatting
This was selected as the best answer
MPIMPI
Ahh... dang cross-site scripting filter. Erased my tags. What JimRae said basically.
Cool_DevloperCool_Devloper

Hi Yori/Jim,

I have created a Custom VF Screen with a Custom Controller.

The issue is that i am unable to show the Approval History related list on the Custom Screen, even though i am using the below code:

<apex:relatedList list="ProcessSteps" ></apex:relatedList>

Is there something missing out here? Did the same thing work for you guys? I have created an Approval Process on the custom object also.

Please help me .....
 
Many Thanks,
Cool_D
JimRaeJimRae
Maybe you should set up the page using a standardcontroller for your custom object, and then extend it with your custom controller using a controller extension.  I have always used the related lists with standardcontroller pages, and have not had an issue.
Cool_DevloperCool_Devloper

Thanks a ton Jim for the help extended.

Can you please elaborate or direct me to some reference about "Controller Extension". I am not too sure of how that works :(

Also, my page is totally a custom developed VF page so i need to use the Custom Controller for the requisite functionality. I hope this concept works in this scenario.

Really appreciate your help Jim!!

Many Thanks

JimRaeJimRae
You can see a lot of detail in the VF documentation about controllers and extensions, but basically it works like this.

You probably have your page set up like this (plus whatever other elements you are adding:

Code:
<apex:page contoller="mycustomcontroller" >

 
Code:
<apex:page standardcontoller="mycustomobject__c" extensions="mycustomcontroller" >

 
You need to change your controller to extend the standard object functionality, something like this:

Code:
public class myCustomcontroller{
private final myCustomObject myobj;
// The extension constructor initializes the private member
// variable myobj by using the getRecord method from the standard
// controller. This eliminates the need to pass the id of the object in the URL
public myControllerExtension(ApexPages.StandardController stdController) { this.myobj = (myCustomObject)stdController.getRecord(); }

 
If you can't get this to work, I don't know how the relatedlist tag would know what object you are looking for on the page.


Cool_DevloperCool_Devloper

Hello Jim,

I must say you saved my life :)

Many thanks for the elaborate post as i was able to use this concept to achieve the result i.e. Approval History appearing on my custom VF screen.

Just one more help ..... if i am trying to recall the submitted record, i am being redirected to the standard detail page of that record. But i want to come back to the custom VF page itself.
 
Any idea if this can be done and how?
 
Appreciate your kind help!!
 
Thanks
JimRaeJimRae
You didn't specify how you were recalling your submitted, but I would guess you need to override the edit button with your visualforce page.
If you go to your object in the setup, create, objects, you should see the standard buttons, and have an option for override.  Since you now are using the Standardcontroller with an extension, you can override directly with your VF page. If you were using a custom controller only, you could not.

You may want to override both the view and edit buttons.


Cool_DevloperCool_Devloper

The Recall Button is a standard button which comes as part of the standard Approval Process.

After submitting a record for approval, i can still recall it by clicking this button. But i am not sure how can I over-ride it?

Cool_D

JimRaeJimRae
Sorry, I misunderstood what you meant, now I understand.  I have not been able to find a way to disable or override the buttons related to the approval process. Your only option might be to create a custom related list, and add your own buttons to simulate the functionality you do need.
Cool_DevloperCool_Devloper
Yes Jim .... even i was thinking on those lines.
 
Anyways, thanks a ton for all the help!! I have come far with this :)
 
Cool_D
Cool_DevloperCool_Devloper

Hello Jim,

I am back again with a query :)

Actually, i could display the Approval History with the method specified by you. But still i am facing an issue with the "History" related list of my Custom Object.

I can see the Parent-Child relationship in the WSDL with the name of "Histories", but when i try to display it on the custom VF screen, its gives an error saying this relationship is not valid.

I have added this on the standard page and have set the history tracking as well on some fields.

Can you please help me, if i am missing something? I am using this tag:

 <apex:relatedList list="Histories" ></apex:relatedList>

Many Thanks,

Cool_D 

JimRaeJimRae
According to another post I found by Ron Hess, the Histories related list is a special case and can't be displayed using the relatedlist tag. However, you can create a pageblocktable to display the list.  In my testing it works, but gives an error when the field is "created", so I had to exclude that from my query.

Here is the code snippet that Ron posted, you would need change it from case, to your custom object:

Code:
<apex:page standardcontroller="case" >
    <apex:form >
        <apex:pageBlock id="thePageBlock">
            
            <apex:pageBlockTable value="{!case.Histories}" var="h">
                <apex:column headerValue="Date"  value="{!h.createddate}"/>
                <apex:column headerValue="What" value="{!h.field}"/>
                <apex:column headerValue="From" value="{!h.oldvalue}"/>
                <apex:column headerValue="To"   value="{!h.newvalue}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

mitz.chauhan@gmail.commitz.chauhan@gmail.com

great posts guys...

 

i have a (very) related question...........

 

managed to get the Approval History list on a VF page, but am struggling to get the 'Items to approve' related list to appear on a VF page.

 

tried a few variations, got as far as:

 

<apex:relatedList subject="{!contract} list="relatedApprovalList"> </apex:relatedList>

 

....but i need to reference the id of the record - in this case, a stanndard SF object - 'Contracts'. I've tried id="{!contract.id}", but no joy.

 

any ideas?

 

Mitesh