You need to sign in to do that
Don't have an account?

To Add a new row while clicking on AddRow button,
Hi Experts,
Please clarify my doubt,, i am trying to create save,clear,addrow,clone button, and i have created now upto save and clear, want to cover another two button methods, anybody plz add a few lines to bellow apex class and vf page, its needfull to me. Thanks in advance,,
VF Page :
-------------------------------
<apex:page controller="SaveAccount">
<apex:form >
<apex:pageblock title="Enter Account Details">
<apex:pageblockSection id="Refreshthis">
<apex:inputtext value="{!AcName}" label="Acc_Name"/>
<apex:inputtext value="{!AcPhone}" label="Acc_Phone"/>
</apex:pageblockSection>
<apex:pageblockButtons location="Bottom" >
<apex:commandButton action="{!Save}" value="Save"/>
<apex:commandButton action="{!Clear}" value="Clear"/>
<apex:commandButton action="{!AddRow}" value="AddRow"/>
</apex:pageblockButtons>
</apex:pageblock>
<apex:pageblock >
</apex:pageblock>
</apex:form>
</apex:page>
--------------------------------------
Class :
public with sharing class SaveAccount {
public PageReference AddRow() {
// Add lines here
return null;
}
public PageReference Clear() {
AcName = '';
AcPhone = '';
return null;
}
public PageReference Save() {
account ac = new account();
ac.name = AcName;
ac.phone = AcPhone;
insert ac;
PageReference orderPage = new PageReference('/' + ac.id);
orderPage.setRedirect(true);
return orderPage;
// return null;
}
public String AcPhone { get; set; }
public String AcName { get; set; }
}
Please clarify my doubt,, i am trying to create save,clear,addrow,clone button, and i have created now upto save and clear, want to cover another two button methods, anybody plz add a few lines to bellow apex class and vf page, its needfull to me. Thanks in advance,,
VF Page :
-------------------------------
<apex:page controller="SaveAccount">
<apex:form >
<apex:pageblock title="Enter Account Details">
<apex:pageblockSection id="Refreshthis">
<apex:inputtext value="{!AcName}" label="Acc_Name"/>
<apex:inputtext value="{!AcPhone}" label="Acc_Phone"/>
</apex:pageblockSection>
<apex:pageblockButtons location="Bottom" >
<apex:commandButton action="{!Save}" value="Save"/>
<apex:commandButton action="{!Clear}" value="Clear"/>
<apex:commandButton action="{!AddRow}" value="AddRow"/>
</apex:pageblockButtons>
</apex:pageblock>
<apex:pageblock >
</apex:pageblock>
</apex:form>
</apex:page>
--------------------------------------
Class :
public with sharing class SaveAccount {
public PageReference AddRow() {
// Add lines here
return null;
}
public PageReference Clear() {
AcName = '';
AcPhone = '';
return null;
}
public PageReference Save() {
account ac = new account();
ac.name = AcName;
ac.phone = AcPhone;
insert ac;
PageReference orderPage = new PageReference('/' + ac.id);
orderPage.setRedirect(true);
return orderPage;
// return null;
}
public String AcPhone { get; set; }
public String AcName { get; set; }
}
Plz find the below URl check how to remove r add row .i think its helpful for u
http://salesforceworld4u.blogspot.in/2014/01/addremove-functionality-in-vf-page-for.html
regards
Nagaraj
plz see below link it will helpfull to you.
http://www.infallibletechie.com/2012/06/dynamically-adding-rows-in-apex.html
regards,
Eswar prasad
{
//public List<Account> accList{get;set}
public List<Account> accAddList{get;set;}
//public Account acc{get;set;}
public SaveAccount()
{
accList = new List<Account>();
}
public voidAddRow()
{
accAddList.add(new Account());
}
public PageReference Clear()
{
AcName = '';
AcPhone = '';
return null;
}
public PageReference Save()
{
if(accAddList.size>0)
{
insert accAddList;
}
PageReference orderPage = new PageReference('/' + ac.id);
orderPage.setRedirect(true);
return orderPage;
}
public String AcPhone { get; set; }
public String AcName { get; set; }
}
<apex:page controller="SaveAccount">
<apex:form >
<apex:pageblock title="Enter Account Details">
<apex:pageblockSection id="Refreshthis">
<apex:pageBlockTable value="{!accAddList}" var="acc1">
<apex:column headerValue="Account Name">
<apex:inputField value="{!acc1.Name}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!acc1.Phone}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageblockSection>
<apex:pageblockButtons location="Bottom" >
<apex:commandButton action="{!Save}" value="Save"/>
<apex:commandButton action="{!Clear}" value="Clear"/>
<apex:commandButton action="{!AddRow}" value="AddRow"/>
<apex:commandButton action="{!clone}" value="Clone"/>
</apex:pageblockButtons>
</apex:pageblock>
</apex:form>
</apex:page>
The code shared by Amit is good, but he initialized wrong list of account in constructor.
Kindly add below lines to code:
public SaveAccount()
{
accAddList = new List<Account>();
}
Regards
Mohit Bansal