6

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':

enter image description here

And that permset has access to the removed field:

enter image description here

And that permset has full CRUD/view all/modify all on the parent object:

enter image description here

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.

3
  • 2
    Maybe it has to do with whether or not the MD is reparentable?
    – Adrian Larson
    Commented Jan 14, 2021 at 19:39
  • @AdrianLarson Interesting idea; I am passing accessType of 'AccessType.UPSERTABLE' since this LWC will also be used to edit existing records. I'll do some testing and report back. Commented Jan 14, 2021 at 19:42
  • 1
    @AdrianLarson Great call, switching from Upsertable to Insertable made it work; I'll need to restructure my code a bit, but now I understand the behavior. Would you like to add an answer that I can accept? Commented Jan 14, 2021 at 19:47

1 Answer 1

6

It may well be related to whether or not your relationship is reparentable. If not, the field would not be updateable.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .