I'm leaning a VF Page Creation. I'm try to create page from which i can save muliple account. in which i've to implement, add and remove row. i'm able to add row perfectly as required but unable to delete row.
My VF Page code:
<apex:page standardController="Account" sidebar="false" extensions="Accountextension">
<apex:form >
<apex:pageBlock title="Account Records Edit" id="Refresh" >
<apex:pageBlockButtons location="both">
<apex:commandButton value="Save" action="{!save}" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Adding Multiple Accounts" columns="1">
<apex:pagemessages />
<apex:pageBlockTable value="{!Acc}" var="a" >
<apex:variable value="{!0}" var="rowNumber" />
<apex:column headerValue="Action">
<apex:commandButton action="{!removeNewObject}" value=" X " >
<apex:param name="rowIndex" value="{!rowNumber}" />
</apex:commandButton>
<apex:variable var="rowNumber" value="{!rowNumber+1}"/>
</apex:column>
<apex:column headerValue="Account Name">
<apex:inputField value="{!a.Name}"/>
</apex:column>
<apex:column headerValue="Account Type">
<apex:inputField value="{!a.Type}"/>
</apex:column>
<apex:column headerValue="Industry">
<apex:inputField value="{!a.Industry}"/>
</apex:column>
</apex:pageBlockTable>
<apex:commandLink value="Add Row" action="{!AddRow}" reRender="Refresh" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Controller is :
public with sharing class Accountextension {
public List<Account> Acc {get;set;}
public Integer rowIndex { get; set; }
public Accountextension(ApexPages.StandardController controller) {
this.acc = new list<account>();
this.acc.add(new Account());
}
public PageReference AddRow()
{
this.acc.add(new Account());
return null;
}
public PageReference removeNewObject(){
Integer indexVal = Integer.valueof(system.currentpagereference().getparameters().get('rowIndex'));
system.debug('%%%%%%%%'+rowIndex);
system.debug('%%%%%%%%'+indexVal );
if(acc[indexVal-1].Id != null)
acc.remove(indexVal-1 );
return null;
}
}
Screen shot is
When I click on delete button ("X") it gives me error like
System.NullPointerException: Argument cannot be null. error at; Integer indexVal = Integer.valueof(system.currentpagereference().getparameters().get('rowIndex'));
I'm unable to understand what wrong here: