You need to sign in to do that
Don't have an account?
SeanCeno
Delete button only deleting top row?
My delete button seems to only be deleting the top row, not the specified row. A {!rowNumber+1} deletes the 2nd row each time, then hits an out of bounds error, naturally. Can anybody see what I'm doing wrong?
public void addRow(){ expenseLineItemAllocationList.add(new Expense_Line_Item_Allocation__c()); } public void saveCompany(){ for(Expense_Line_Item_Allocation__c ela: expenseLineItemAllocationList) ela.Expense_Line_Item_Detail__c = expenseLineItem.Id; upsert expenseLineItemAllocationList; } public integer rowIndex {get; set;} public Expense_Line_Item_Allocation__c del; public void deleteRow(){ //System.debug('row to be deleted ' + rowIndex ); //System.debug('row item to be deleted '+expenseLineItemAllocationList[rowIndex]); del = new Expense_Line_Item_Allocation__c(); del = expenseLineItemAllocationList.remove(rowIndex); }
<apex:pageBlockSection id="Allocation" title="Allocate Expenses" Columns="1" collapsible="false" rendered="{!(expenseLineItem.AllocationCheckbox__c == true)}"> <apex:outputLabel value="Please select the Managed Company and the percentage amount you wish to allocate to it. Press Save in order to see the Allocation Split value." /> <apex:variable var="rowNumber" value="{!0}"/> <apex:pageBlockTable id="allocationTable" var="allocation" columns="4" value="{!expenseLineItemAllocationList}"> <apex:column headerValue="Managed Company"> <apex:inputField value="{!allocation.Product__c}"/> </apex:column> <apex:column headerValue="Allocation %"> <apex:inputField value="{!allocation.Allocation__c}"/> </apex:column> <apex:column headerValue="Allocation Split"> <apex:outputField value="{!allocation.Allocation_Split__c}"/> </apex:column> <apex:column headerValue="Action"> <apex:commandButton value="Delete" action="{!deleteRow}" rerender="Allocation"> <apex:param name="Allocation" value="{!rowNumber}" assignTo="{!rowIndex}"/> </apex:commandButton> </apex:column> <apex:variable var="rowNumber" value="{!rowNumber}" /> </apex:pageBlockTable> <apex:commandButton value="Add Row" action="{!addRow}" rerender="allocationTable"/> </apex:pageBlockSection>
All Answers
Hope below code will helps you
Mark it as a solution if it helps you
Thanks for the respone. The code compiles, but it's still deleting the only the top row first. Do I need to change my variable in my VF page to {!del}?
Thanks for the response. Still the same result. Does the fact that the number of rows initially created comes from a multi-select picklist? Here's the logic in the getter for that:
Basically if the user selects to do a custom allocation after selecting the companies, a new section drops down with the first field (picklists with the same values as multi-select) populated with the multi-select options. Then the user can choose the percentage to multiply it by. I want these rows to be editable though. Add row works fine, but delete not so much.
may have to take a look at the debug log when clicking save
Here is the code for a Save and New button. As you can see the saveCompany() method is in there:
Oops, was was removing the row before adding the delete Id.
deleteItems.add(expenseLineItemAllocationList[rowIndex]);
Do I need to instantiate deleteItems somewhere?
hmm maybe you need to evaluate if the list index is not null first..
delete deleteItems;
DML requires SObject or SObject list type: List <id>
Not sure why it's throwing the error.
Attempt to de-reference a null object
Error is in expression '{!deleteRow}' in component <apex:commandButton> in page expensereport: Class.ExpenseReport.deleteRow: line 854, column 1