I am building and LWC which uses lightning-record-edit-form
to create an object, then calls an Apex controller method to create a list of M-D children of the newly created object. In my current test, the parent save is successful, and I fetch the new parent record Id in the onsuccess
handler of the record edit form, add it to the new children, and pass them to Apex, where I call stripInaccessible
. That is stripping the parent M-D field, but I don't know why. My user has a permset which:
- grants full CRUD/ViewAll/Modify all to the child and full FLS to all fields
- grants full CRUD/ViewAll/Modify all to the parent and full FLS to all fields
The children all have the parent field set to the new parent, which is owned by the user (it was just created). I can't figure out why stripInaccessible
is doing it.
I wave confirmed in the debug log that the child record(s) being sent to Apex to be saved all have the correct Id for the MD parent field, matching the newly-created parent record. Here's debug log output showing getRemovedFields()
after stripInaccessible
is called:
{"Collections_Hardship_Payment__c":["Collections_Hardship_Payment_Agreement__c"]}
All testing is done as the default user in my scratch org, who has the persmet 'Collections Admin':
And that permset has access to the removed field:
And that permset has full CRUD/view all/modify all on the parent object:
Why is the MD parent field being stripped. What am I missing?
Edit Based on Adrian's answer, I discovered that my issue was the way I called stripInaccessible
. I was passing accessType of 'AccessType.UPSERTABLE' since this LWC will also be used to edit existing records (next phase of dev). Once I switched to AccessType.INSERTABLE, the problem went away. I am now checking the the child records have IDs, to determine whether to Insert or Update, and making the appropriate stripInaccessible
call.