You need to sign in to do that
Don't have an account?

Page Redirect Issue
Hi Experts,
I have 3 custom objects:
Person__c
Vehicle__c
Person_Vehicle__c
The Person_Vehicle__c is child of Person and it has lookup relationship with Vehicle.
I created a VisualForce page and placed it in person tab. The VisualForce page lists all child records for the person whose data is being displayed. The display in person page is something like:
Person Name Vehicle
Tirtha Maruti 800
Tirtha Zen
The ‘Vehicle’ items are commandLink so that if I click ‘Maruti 800’, the page redirects to ‘Maruti 800’ detail page.
The following is my page and controller code:
public class VehicleListControllerClass{ public String getPersonName(){ ID pId = System.currentPageReference().getParameters().get('id'); String name = [Select Name from Person__c where id=:pId].Name; return name; } public List<Person_Vehicle__c> getVehicleList(){ ID pId = System.currentPageReference().getParameters().get('id'); List<Person_Vehicle__c> data = new List<Person_Vehicle__c>( [Select p.Person__r.Name, p.Vehicle__c, p.Vehicle__r.Name from Person_Vehicle__c p where p.Person__c=:pId]); return data; } public PageReference OpenVehicle(){ PageReference page = System.CurrentPageReference(); ID vId = page.getParameters().get('vehicleId'); return new PageReference('/'+vId); } } <apex:page controller="VehicleListControllerClass"> <apex:form> <apex:pageBlock title="Vehicle List for {!personname}"> <apex:pageBlockList value="{!vehicleList}" var="v"> <apex:column value="{!v.Person__r.Name}"/> <apex:column> <apex:commandLink value="{!v.Vehicle__r.Name}" action="{!OpenVehicle}"> <apex:param name="vehicleId" value="{!v.Vehicle__c}"/> </apex:commandLink> </apex:column> </apex:pageBlockList> </apex:pageBlock> </apex:form> </apex:page>
The first issue:
When I click on any vehicle item, it works nicely and respective vehicle detail is displayed on the page. The url becomes:
https://na2.salesforce.com/a0340000004dX5AAAU?inline=1
But, if I try to do the same with ‘right-click-->Open link in new tab’, it doesn’t work and instead displays error ‘URL No Longer Exists’. The url, in this case, becomes:
https://na2.salesforce.com/servlet/servlet.Integration?lid=0664000000000JY&ic=1#
The second issue:
The second problem is that I do not see the column header for ‘vehicle’ (second column). I also tried to use facet, but it also didn’t work:
<apex:column> <apex:facet name="header">Vehicle</apex:facet> <apex:commandLink value="{!v.Vehicle__r.Name}" action="{!OpenVehiclePage}"> <apex:param name="vehicleId" value="{!v.Vehicle__c}"/> </apex:commandLink> </apex:column>
Please suggest.
Thanks,
-Roshan
- Using an action method for redirect navigation is often overkill (as it looks to be in your example) - I would switch to <apex:outputLink> in this situation (should also provide a solution for issue #1 below):
becomes
- Embedded SOQL already returns a list so there is no need to construct another one, e.g.:
Message Edited by dchasman on 04-29-2008 06:17 PM
Your both of the solutions worked finely.
But there occurred a little problem on my first issue. Mainly this visualforce page is placed inside the Person tab by creating a new section in Person's page layout. After implementing your suggestion (by using outputLink tag), when I clicked the 'Vehicle' link, the detail of respective vehicle displayed within the section with parent tab (Person) remained unchanged. What I wanted was to refresh the whole page and display just the Vehicle detail page.
So I added another tag 'target="_top"'...
...and it worked!
I just want your concern on "Is it a good approach?"
As far as constructing another list while SOQL already returns 'list', I wanted to manipulate some of the field values according to my requirement like...
This is because, I was unable to use 'IF' condition in visualforce page and I don't know how to pass parameter from visualforce page to controller.
And thanks again for your help.
-Roshan