You need to sign in to do that
Don't have an account?
MissaJ
Can't get add a row to work or clone to work..Help
I have a object that a user needs to enter some data in a table format. Then they may want to add another record. They need to pull the ID that is being used to on the first row to the new row. I can't get the Add/clone to work. Any help is appreciated.
public with sharing class FacilityPayChangeController {
public Facility_Payrate_Change__c newPayChange {get; set;}
public FacilityPayChangeController()
{
ID dlRequestId = ApexPages.currentPage().getParameters().get('dlRequestId');
newPayChange = new Facility_Payrate_Change__c(DL_Request__c=DLRequestID);
}
public PageReference copyFPC() {
String dlRequestID = ApexPages.currentPage().getParameters().get('dlRef');
if (dlRequestID != null)
{ newPayChange = new Facility_Payrate_Change__c(DL_Request__c=DLRequestID);
}
return null;
}
public PageReference save(){
insert newPayChange;
PageReference home = new PageReference('/home/home.jsp');
home.setRedirect(true);
return home;
}
}
VF Page
<apex:page Controller="FacilityPayChangeController" showHeader="False">
<apex:form >
<apex:PageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Submit" action="{!save}" rerender="error"/>
<apex:commandButton action="{!copyFPC}" value="Add another"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!newPayChange}" var="newPayChange" id="table">
<apex:commandLink action="{!copyFPC}" value="Add another"/>
<apex:column headerValue="DL Request #">
<apex:inputField value="{!newPayChange.DL_Request__c}"/>
</apex:column>
<apex:column headerValue="Shift Type">
<apex:inputField value="{!newPayChange.Shift_Type__c}"/>
</apex:column>
<apex:column headerValue="Coverage Type">
<apex:inputField value="{!newPayChange.Coverage_Type__c}"/>
</apex:column>
<apex:column headerValue="New Start Day">
<apex:inputField value="{!newPayChange.New_Shift_Start_Day_of_Week__c}"/>
</apex:column>
<apex:column headerValue="New Start Time">
<apex:inputField value="{!newPayChange.New_Shift_Start_Time__c}"/>
</apex:column>
<apex:column headerValue="Requested Rate">
<apex:inputField value="{!newPayChange.Requested_Rate_Per_Hour__c}"/>
</apex:column>
<apex:column headerValue="Hours Impacted">
<apex:inputField value="{!newPayChange.Hours_Impacted__c}"/>
</apex:column>
<apex:column headerValue="Effective Date">
<apex:inputField value="{!newPayChange.Effective_Date__c}"/>
</apex:column>
</apex:PageBlockTable>
</apex:PageBlock>
</apex:form>
</apex:page>
For adding another row... you just need to allocate memory by creating a new instance and add that instance to the returning list.
Some thing like below.
Public list<Account> acclist {get;set;}
public void fun(){
Account a = new Account();
accList.add(a);
}
You are backing your table with a single instance of Facility_Payrate_Change__c. That means there will only ever be one row in the table. If you want to be able to show multiple rows, you'll need to back the table with a list of these objects.
Revised code below - not tested, so there may be typos!