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>