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
Ilarion Tokarskiy 10Ilarion Tokarskiy 10 

ContactShare doesn`t work

The user does not see the contact when adding the ContactShare

Code in Trigger:
User user = [SELECT Id FROM User WHERE Alias = 'mmana']; Contact contact = [SELECT Id FROM Contact LIMIT 1]; ContactShare contactShare = new ContactShare();
contactShare.Contact = contact;
contactShare.ContactId = contact.Id;
contactShare.UserOrGroupId = user.Id; contactShare.ContactAccessLevel = 'Edit';
insert contactShare;

Organization-Wide Defaults
Account: Private
Contact: Private

How can i solve this problem with Apex?
imrohitimrohit

Hello Ilarion Tokarskiy 10 

Please try to associate account  to the contact which you are inserting for sharing with other users because

Contacts may not be shared independently from Accounts, so Contact Sharing Rules are not applied (even if they are defined).

you can follow this link to get more info.

https://salesforce.stackexchange.com/questions/232644/contact-sharing-rules-no-account