List button:
Visualforce page:
<apex:page controller=”AddingInterestsController”>
<apex:form >
<apex:variable var=”rowNum” value=”{!0}” />
<apex:pageBlock >
<apex:variable var=”rowNum” value=”{!0}” />
<apex:pageBlockTable value=”{!interestList}” var=”int”>
<apex:facet name=”footer”>
<apex:commandLink value=”Add” action=”{!insertRow}”/>
</apex:facet>
<apex:column headerValue=”Name”>
<apex:inputField value=”{!int.Name}”/>
</apex:column>
<apex:column headerValue=”Description”>
<apex:inputField value=”{!int.Description__c}”/>
</apex:column>
<apex:column headerValue=”Delete” >
<apex:commandLink style=”font-size:15px; font-weight:bold; text-align:center;color:red;” value=”X” action=”{!delRow}”>
<apex:param value=”{!rowNum}” name=”index” />
</apex:commandLink>
<apex:variable var=”rowNum” value=”{!rowNum+1}”/>
</apex:column>
</apex:pageBlockTable>
<apex:pageBlockButtons >
<apex:commandButton value=”Save” action=”{!insertIntests}”/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Apex Controller:
public class AddingInterestsController {
Id empId;
public List<Interest__c> interestList {get;set;}
public Integer rowNum{get;set;}
public AddingInterestsController(){
empId = ApexPages.currentPage().getParameters().get(’empId’);
interestList = new List<Interest__c>();
interestList.add(new Interest__c());
}
public void insertIntests(){
insert interestList;
}
public void insertRow(){
interestList.add(new Interest__c());
}
public void delRow(){
rowNum = Integer.valueOf(apexpages.currentpage().getparameters().get(‘index’));
interestList.remove(rowNum);
}
}
Output: