I came upon this error when I am assigning the custom object to the master standard object.
Eg. accountId derived from a query
Then I get this error.
The fix was actually easy. I just rewrote it to assign the master id on instantiating the child object.
Hope somebody finds this useful.
5 thoughts on “Master-Detail: Field is not writable error on Apex”
This solution is very helpful and easy also. Thanks 🙂
Glad you found it helpful.
Thank you so much for this blog.Glad I found it
What if we want to update the Account__c field ??
The example is for an insert DML. For update operation as the child record already exists, updating the record relationship should work fine as is.