You need to sign in to do that
Don't have an account?
Ethan West
Adding multiple rows; not working.
Hi -
I have a Mass Create Button that I'm trying to get functionality to work on but it doesn't seem to be going to plan. Can someone assist?
I'm trying to get multiple rows to be created when I click on the "Add Assignment Row" button, but it just refreshes the page and shows a single row again (see button and row below).
This is my current VF Page:
<apex:page standardController="pse__Assignment__c" recordSetVar="unused" extensions="AddanotherAssignmentController" > <apex:enhancedList type="pse__Assignment__c" height="300" rowsPerPage="10" id="ListViewID"/> <apex:form > <apex:pageBlock > <apex:pageBlockTable value="{!listAssignment}" var="TC"> <apex:column headerValue="Assignment Name"> <apex:inputField value="{!TC.Name}"/> </apex:column> <apex:column headerValue="Resource"> <apex:inputField value="{!TC.pse__Resource__c}"/> </apex:column> <apex:column headerValue="Project"> <apex:inputField value="{!TC.pse__Project__c}"/> </apex:column> <apex:column headerValue="Candidate"> <apex:inputField value="{!TC.Candidate__c}"/> </apex:column> <apex:column headerValue="Bill Rate"> <apex:inputField value="{!TC.pse__Bill_Rate__c}"/> </apex:column> <apex:column headerValue="Start Date"> <apex:inputField value="{!TC.Start_Date__c}"/> </apex:column> <apex:column headerValue="End Date"> <apex:inputField value="{!TC.End_Date__c}"/> </apex:column> <apex:column headerValue="Monday Hours"> <apex:inputField value="{!TC.Monday_Hours__c}"/> </apex:column> <apex:column headerValue="Tuesday Hours"> <apex:inputField value="{!TC.Tuesday_Hours__c}"/> </apex:column> <apex:column headerValue="Wednesday Hours"> <apex:inputField value="{!TC.Wednesday_Hours__c}"/> </apex:column> <apex:column headerValue="Thursday Hours"> <apex:inputField value="{!TC.Thursday_Hours__c}"/> </apex:column> <apex:column headerValue="Friday Hours"> <apex:inputField value="{!TC.Friday_Hours__c}"/> </apex:column> <apex:column headerValue="Saturday Hours"> <apex:inputField value="{!TC.Saturday_Hours__c}"/> </apex:column> <apex:column headerValue="Sunday Hours"> <apex:inputField value="{!TC.Sunday_Hours__c}"/> </apex:column> </apex:pageBlockTable> <apex:pageBlockButtons > <apex:commandButton value="Add Assignment Row" action="{!addAssignment}"/> <apex:commandButton value="Save Assignments" action="{!save}"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </apex:page>
and this is my current Apex Class Page:
public class AddanotherAssignmentController { public AddanotherAssignmentController(ApexPages.StandardSetController controller) { } pse__Assignment__c assignment = new pse__Assignment__c(); public list<pse__Assignment__c> listAssignment{ get; set; } public AddanotherAssignmentController() { listAssignment=new list<pse__Assignment__c>(); listAssignment.add(assignment); } Public void addAssignment() { pse__Assignment__c TC = new pse__Assignment__c(); listAssignment = new List<pse__Assignment__c>(); listAssignment.add(TC); } public PageReference saveAssignment() { for(Integer i=0; i<listAssignment.size(); i++) { insert listAssignment; } return Page.Allassignmentsaved; } }
Any interpretation as to why I'm only getting one row added at a time would be very useful.
Many thanks,
Ethan
Greetings to you!
I have made a few changes to your code. Please use below code:
Visualforce:
Controller:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
Hi Khan,
I tried your code and it doesn't seem to be saving records, and for some reason this one isn't taking me to my Allassignmentsaved reference either.
Any assistance as to why this isn't saving the records? [Same issue happening with my other open case]
Kind regards,
Ethan
Try the below code
Apex Class
VF page
Thanks