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

VF Controller save multiple child records against 1 master record
Hi,
I have a master object called Expense Form and a child object called Expense Item. I trying to create a wizard which will allow me to save multiple expense item records against an expense form object. With some help I have gotten this far, I have highlighted in red the part which I think is wrong.
With this code I am getting the following error: Expression cannot be assigned at line -1 column -1.
Any help would be great.
public class newExpensesController { Expense_Form__c Eform; Expense_Item__c Eitem; public Expense_Form__c getEform() { if(Eform == null) Eform = new Expense_Form__c(); return Eform; } public Expense_Item__c getEitem() { if(Eitem == null) Eitem = new Expense_Item__c(); return Eitem; } public PageReference cancel() { PageReference EformPage = new ApexPages.StandardController(Eform).view(); EformPage.setRedirect(true); return EformPage; } public PageReference save() { List<Expense_Form__c> Eitems=new List<Expense_Form__c>(); for (Expense_Form__c Eform : Eform) { Expense_Item__c Eitem=newEitems (Expense_Form__c.id=Eform.id); Eitems.add(Eitem); } insert Eform; } { PageReference EformPage = new ApexPages.StandardController(Eform).view(); EformPage.setRedirect(TRUE); } }
There's a couple of other issues here:
1. Eform is an instance of an Expense_Form__c, so iterating it doesn't make sense.
2. You are declaring eitems as a list of Expense_Form__c records, but then adding Expense_Item__c records to it.
All Answers
here is updated code
There was only issue while you create New object of Expense_Item__c
Hope it will help you
Thanks,
Bala
There's a couple of other issues here:
1. Eform is an instance of an Expense_Form__c, so iterating it doesn't make sense.
2. You are declaring eitems as a list of Expense_Form__c records, but then adding Expense_Item__c records to it.
Thanks for all your help.