
Code is working perfectly fine and I am able to see User gets added to "User and Group Sharing" section however when User logs in then he still gets "Insufficient Access" error for that contact.Is there issue with Contact which not directly linked to Account? I am not sure where is it getting wrong.Please let me know in case you have gone through such issue.global class ContactShareController
{
webservice static string shareContact(string conId)
{
ContactShare con = new ContactShare();
con.ContactId = conId;
con.ContactAccessLevel = 'Edit';
con.RowCause = 'Manual';
con.UserOrGroupId = '00528000000kIX8';
Database.SaveResult sr = Database.insert(con,false);
string strMsg = '';
if(!sr.isSuccess())
{
Database.Error err = sr.getErrors()[0];
strMsg = 'Unable to grant sharing access due to following exception: ' + err.getMessage();
}
else
{
strMsg = 'Shared with ' + con.id;
}
return strMsg;
}
}
5 Antworten

Hi Tushar,Thanks for reply.I have gone through lots of document as well as done a POC for apex share and came to conclusion thatsApex Share does not work for standard object sharing as it works same as Manual sharing and manual sharing is not applicable for Private Contact.So work around is as below -1) Create Dummy Account per 10K Contacts to avoid Account Skew (https://developer.salesforce.com/blogs/engineering/2012/04/avoid-account-data-skew-for-peak-performance.html)Performance issue.2) Create Rollup summary field on Account to check if it has less than or equal to 10K associated Contacts.3) Create Validation Rule on Account which will fire on Rollup summary field count and will not allow more than 10K Contact associated with that Account.4) Create another Dummy Account if previous Dummy Account reaches to 10K associated Contacts.Let me know in case any one has better solution.