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
Shivangi SrivastavaShivangi Srivastava 

Can not create Sharing record for Community users

I have a custom object 'Plan'.I am trying to share it  with all the community users(which contains users with different profiles) through apex code(Plan_share object)
 BUT facing an exception as:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: unknown (invalid user or group: 005U0000002hje3): [unknown]

whereas If I go the same Id i.e;005U0000002hje3 in my org ,there exist a valid community user with this id.

Can anybody suggest what I am missing here??

geosowgeosow
Is your user a Customer Community license?  You cannot add Customer Community users to sharing objects (only Partner Community users can be added).
Shivangi SrivastavaShivangi Srivastava

Yes,my user has a Customer Community license.

Is there any work around for this?  

geosowgeosow
You can set the Organization-Wide Defaults to public read only or public read-write and make sure grant access using hierarchies is unchecked.  

Give that a shot.  If that doesn't work for any reason, you will have to make a Visualforce page that has an extension class where you query the object and specify "without sharing" in your class.
Shivangi SrivastavaShivangi Srivastava

#1) You can set the Organization-Wide Defaults to public read only or public read-write and make sure grant access using hierarchies is unchecked.

     - Tried with this approach,not working seems something is missing.

#2) If that doesn't work for any reason, you will have to make a Visualforce page that has an extension class where you query the object and specify "without sharing" in your class 

     - My class is already 'without sharing' but doesn't help in removing the exception.