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.

3 responses to “Master-Detail: Field is not writable error on Apex”

  1. Abinaya says:

    This solution is very helpful and easy also. Thanks 🙂

  2. lopau says:

    Glad you found it helpful.

  3. uma says:

    Thank you so much for this blog.Glad I found it

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.