2

I'm creating a vf component that displays a list of records. I would like to have an edit button within the pageblock table to link to the individual records, however, I'm not sure how to pull the id's out of the list? Thanks in advance for any pointers. Below is my code:

Custom controller:

public class InsurancePolicy {
public LLC_BI__Loan__c loan1 {get;set;}
public List<Insurance_Policy__c> ins {get;set;}


public LLC_BI__Loan__c getloan() {
            loan1 = [Select name FROM LLC_BI__Loan__c 
                     WHERE id = :ApexPages.currentPage().getParameters().get('id')];
    return loan1;
}


public InsurancePolicy()
    {
        ins = [SELECT   Id, name,Actual_Cash_Value__c, Coverage_Amount__c, Relationship__c, Days_Past_Expiration__c, 
                        Days_Until_Expiration__c, Deductible__c, Insurance_Company__c, RelatedLoan__c, Policy_Expiration_Date__c, 
                        Policy_Issue_Date__c  
               FROM Insurance_Policy__c
               WHERE RelatedLoan__c = :ApexPages.currentPage().getParameters().get('id')];

    }    


public PageReference edit() {
    PageReference nextpage= new PageReference('/'+ins[0].id);
       return nextpage;
}

}

Visualforce page:

<apex:component controller="InsurancePolicy"> 
<apex:attribute name="InsurancePolicyInfo" description="Attribute on the component."type="String" required="required" />
<apex:form>
<apex:pageBlock >
  <p>
  Insurance policies related to {!loan.name} 
<br/>
<apex:pageBlockTable value="{!ins}" var="ld">
  <apex:column headerValue="Edit Insurance Policy">
    <apex:commandButton action="{!edit}" value="Edit"/>
  </apex:column>
  <apex:column value="{!ld.Policy_Expiration_Date__c}"/>
  <apex:column value="{!ld.Coverage_Amount__c}"/>
  <apex:column value="{!ld.Actual_Cash_Value__c}"/>
  </apex:pageBlockTable>
</p>
</apex:pageBlock>
</apex:form>
</apex:component>

1 Answer 1

3

I am not sure how we can do it with the commandButton(Which need the page reference method to be defined to redirect a particular user to the edit page). My solution uses outputLink but which looks like commandButton using style attribute. Both of these serve same purpose. Here is how I will do it. Instead of,

<apex:commandButton action="{!edit}" value="Edit"/>

I would use,

<apex:outputLink styleClass="btn" style="text-decoration:none;padding:4px;" value="{!URLFOR($Action.Insurance_Policy__c.Edit, ld.id, null, true)}">Edit</apex:outputLink> 

Please let us know if this works.

Thanks, Shailesh

1
  • You could make it as an answer optionally... :) Jul 13, 2016 at 17:10

You must log in to answer this question.

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