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

Field is not Writable error in Trigger
Hello Everyone,
I am facing an error on below trigger
I am noy able to understand why I am getiing this error, all i want to do is just assign the total of my Line Items in Invoice Total.
Please give suggesions.
I am facing an error on below trigger
trigger totaloflineitmoninvc on Line_Item__c(after insert, after update) { Invoice__c [] inv = new List<Invoice__c>(); Set<Id> lineitmid = new Set<Id>(); for(Line_Item__c li : Trigger.New) { lineitmid.add(li.Invoice__c); } Decimal total; Invoice__c[] Invo = [Select Id, Invoice_Total__c, (Select Id, Line_Item_Total__c from line_Items__r) From Invoice__c Where Id IN : lineitmid]; for(Invoice__c invc : Invo ){ total = 0; for(Line_Item__c litm : invc.Line_Items__r ){ total += litm.Line_Item_Total__c; } invc.Invoice_Total__c = total; inv.add(invc); } update inv; }
I am noy able to understand why I am getiing this error, all i want to do is just assign the total of my Line Items in Invoice Total.
Please give suggesions.
If there is master detail relation ship between Invoice__c and line_Item__c better you go for rollup summary field.
What is the relationship between line_Items__c and Invoice__c? If it's master-detail then, by default, you can't 'reparent' the record, that is, write to the Invoice__c field after the detail record has been created. You can, however, selecting 'Allow Reparenting' in the master-detail relationship definition to make it work.
Thanks.