function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Petr Chvala 4Petr Chvala 4 

Security.stripInaccessible issue while upserting records, M-D fields ids are being stripped away

Security.stripInaccessible() will remove all ids of non-reparentable M-D fields from the record while using System.AccessType.UPSERTABLE. 

That will inevitably result in failures for records which are about to be inserted during the upsert as required m-d realtionship id values were removed. 

That makes stripInaccessible fn useless to enfore FLS before commiting to the database if there are any M-D fields involved.

I understand why its happening, but M-D Ids shoud not be removed in this case. And If there are any changed M-D parents for already existing records in dataset, system will prevent it the standard way. 

Security.stripInaccessible()  is a great and easy replacement for previous implementations, but with this flaw it does not cover all the usecases.



  

Ivano Guerini 6Ivano Guerini 6
Hi Petr,
we have encountered the same problem in our developments.
Have you had any more updates from Salesforce, or have you found a work-around for this issue by continuing to use the StripInaccessible method?
Petr Chvala 4Petr Chvala 4

Hi Ivano,

No additional details were provided from Salesforce.

You can work around it by using System.AccessType.CREATABLE for upserts but by doing that you will bypass update access check. Might be fine for some scenarios.

Petr.