1

I am new to salesforce and trying to get this simple requirement working:

  1. Get a list of records on a visualforce page
  2. Have the Name field as hyperlink
  3. When user clicks on hyperlink then take them to detail page where details of that particular records are shown along with their child records

Here is my apex class to render the list view

public with sharing class proposalsController {
        public List<Proposals__c> proposal {get;set;}
        //In constructor
        public ProposalsController(){
            proposal = [Select id, CreatedDate, LastModifiedDate, Proposal_Id__c, Client_Name__c, Proposal_Type__c, Comments__c, Name from Proposals__c limit 1000];
        }
    }

Below is the code visualforce page

<table class="table table-hover" id="proposal-table">
                      <thead><tr><th>Proposal Name</th><th>Client Name</th><th>Proposal Type</th><th>Comments</th></tr></thead>
                      <tfoot><tr><th>Proposal Name</th><th>Client Name</th><th>Proposal Type</th><th>Comments</th></tr></tfoot>
                      <tbody>
                        <apex:repeat value="{!proposal}" var="pr">
                            <tr>
                                <td><apex:form >
                                        <apex:commandLink action="{proposalDetail}" value="{!pr.Name}"/>
                                        <apex:param name="id" value="{!pr.id}"/>
                                    </apex:form>
                                </td>
                            <td>{!pr.Client_Name__c}</td><td>{!pr.Proposal_Type__c}</td><td>{!pr.Comments__c}</td></tr>
                        </apex:repeat>
                      </tbody>
                  </table>    

This completes the first two parts of the requirement. I am not sure how to go about the last part.

Here is what I am trying to add my apex class

public string proposalDetail(){
    String proposalId = ApexPages.currentPage().getParameters().get('id');
    question = [Select id, CreatedDate from Question__c where proposal__c =: proposalId];
}

But I am not sure how to link to this to proposal_detail visualforce page that I have created to show the details.

I have searched and it seems redirect might be an option. What is the best way to achieve this?

0

2 Answers 2

3

For the name links, you don't have to make a server request (which as well as adding complexity to the code would slow down the navigation process). Instead you can render a conventional link directly into the page using:

<apex:outputLink value="{!URLFOR($Action.Proposals__c.view, pr.id)}">
    {!pr.Name}
</apex:outputLink>

See URLFOR function finally explained! for a more detailed explanation and more examples.

PS

To go to a Visualforce page named "MyPage" that accepts an "id" parameter, you can use this syntax:

<apex:outputLink value="{!$Page.MyPage}?id={!pr.id}">
    {!pr.Name}
</apex:outputLink>

Note that it is also possible to replace the standard details page everywhere with your Visualforce page. (Then the first example I show will work.) See Overriding Standard Buttons and Tab Home Pages. Then however the user navigates to the detail view, they will get your Visualforce page.

4
  • But in that case how would I tie this link to my specific method in my controller?
    – Neel
    Commented May 31, 2015 at 12:24
  • The above code results in a normal <a href="..."/> link in the page that navigates straight to the detail page. There is no need to invoke a method in the controller in this case.
    – Keith C
    Commented May 31, 2015 at 12:28
  • But I have custom visualforce page to show the details of the record. So you can say I need to provide take Id from first visualforce page to second visualforce page.
    – Neel
    Commented May 31, 2015 at 12:47
  • See the PS.
    – Keith C
    Commented May 31, 2015 at 14:12
0

You can redirect to other VF page. By using pagereference method.

  public PageReference proposalDetail() 
{

String proposalId = ApexPages.currentPage().getParameters().get('id');
    question = [Select id, CreatedDate from Question__c where proposal__c =: proposalId];

    PageReference redirect = new PageReference('/apex/PageName'); 


    redirect.getParameters().put('id',proposalId); 
    redirect.setRedirect(true); 

    return redirect;
}

Let me know if it does not work for you.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .