I am writing a VF page where I have to show list records with Add/Delete button. when I click Delete (X) button it is deleting the record and removing that particular row. But if I am adding a row with clicking Add button and deleting the same row it is throwing error. It should delete that row which was added that moment. Added my code piece below.
public Pagereference removeRow() {
String SelectedRowId = ApexPages.CurrentPage().getParameters().get('rowid');
for (Integer i = 0; i < subConfigurationList.size(); i++) {
Sub_Task_Configuration__c a = subConfigurationList[i];
if (a.Id == SelectedRowId) {
delete a;
subConfigurationList.remove(i);
break;
}
}
return null;
}
For 1st remove button as shown in pic it is working fine but where there is no record if I click remove(X) button it throwing error.
Error below:
Invalid id: Error is in expression '{!removeRow}' in page task_con: Class.Task_con.removeRow: line 63, column 1
An unexpected error has occurred. Your development organization has been notified.
Please Help me in this!