You need to sign in to do that
Don't have an account?
Jan Kopejtko 2
Help with a simple code
I am writing a simple piece of code that will create a record on the detail side of a relationship upon creation of a record on the master side of relationship, if a checkbox is checked.
However I am recieving an error:
SilaTrigger: execution of AfterInsert caused by: System.FinalException: Record is read-only Trigger.SilaTrigger: line 3, column 1
How do I fix this? I think I am supposed to use "after insert" because I need to know the ID of Master record, so I can populate the detail field with the ID of the master.
Thanks alot
trigger SilaTrigger on Sila__c (after insert) { for(Sila__c a : Trigger.New) { if(a.Checkbox__c = true) { Dependent__c b = new Dependent__c(); b.Name = a.Name; b.Sila__c = a.Id; insert b; } else return; } }
However I am recieving an error:
SilaTrigger: execution of AfterInsert caused by: System.FinalException: Record is read-only Trigger.SilaTrigger: line 3, column 1
How do I fix this? I think I am supposed to use "after insert" because I need to know the ID of Master record, so I can populate the detail field with the ID of the master.
Thanks alot
Please replace "=" with "==" in your condition check like if(a.checkbox__c==true)
Thanks
All Answers
Please replace "=" with "==" in your condition check like if(a.checkbox__c==true)
Thanks
In Apex, == is an equivalent check, = is an assignment of a value to a variable.
Regards