1

I have a remote action method which needs to update Username in User object, but it only works if I define my class as public without sharing. If I use public with sharing instead, updating Username will give me

"EXCEPTION_THROWN|[95]|System.DmlException: Update failed. First exception on row 0 with id 00521000000SxVkAAK; first error: INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: []" error.

Any idea what's causing this? Any way that I can do it without using public without sharing?

FYI, The method is called by a user under Customer Community Login license, & he/she is updating his/her own record, so there should not be permission issue.

1
  • Your user don't have permission to update username. You need to check that. May 31 '16 at 6:46
1

The User record is not created by the community user nor is owned by them. And hence they wont be able to update using With sharing.

3
  • Sorry I forgot to mention this, my community site allows users to self register, so the user records are actually created by a guest user.The strange thing is, my DML also updates other fields like email & CommunityNickname, if I comment the line to update username, the method works perfectly fine & is able to update the other fields.
    – RF18
    May 31 '16 at 8:48
  • As far as i know, even know User's even though created via some automated guest user(probably admin). Check the createdByID feild of user created by self register. If u believe its field accessibility issue,You can check in Security Control>Field Accessibility> User and select ur profile. May 31 '16 at 9:35
  • 1
    Not such to see in Security Control>Field Accessibility> User as most of the fields are not exposed by SF (not even email which my method is able to update).
    – RF18
    Jun 1 '16 at 11:40
0

refer to: https://help.salesforce.com/apex/HTViewHelpDoc?id=users_license_types_communities.htm&language=en_US

and this answer: https://salesforce.stackexchange.com/a/5566/32002

basically this error shows up when you are trying to do something impossible. i.e. edit an read-only system fields.

In this scenario error is thrown because Customer Community license does not have any type of access to User Object. By using "without sharing" that limitation gets lifted. Running in system context ignores even license type limitations of current user. Is this a bug, flaw or feature is an open question.

So, to your question, it is impossible to do it without sharing.

3
  • please check this url :salesforce.stackexchange.com/questions/118005/…
    – Rajesh Kr.
    May 31 '16 at 7:19
  • This is not directly related question. You posted issue related to Case object. Follow my 1st link, Customer Community license has Read, Create, Edit access to Cases. They share same error message but reason entirely different, this error has very wide spectrum of reasons to appear.
    – Andrei.Z
    May 31 '16 at 7:34
  • I have to disagree with "Customer Community license does not have any type of access to User Object", because my DML also updates other fields like email & CommunityNickname, if I comment the line to update username, the method works perfectly fine & is able to update the other fields.
    – RF18
    May 31 '16 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.