I am trying to implement a solution of Account and contact, I have custom field Account status (Picklist field) values - Open, Close

My condition is when the Account status is moved to "Open" the contact record should not be visible to user it should only be visible when its is closed state. below is my code I was trying with Apex sharing but the problem here is

Row cause field of share object is read only field and I can not update.

please review my code and suggest.

public static void controlVisibility(List<Account> acclist, Map<Id,Account> oldMap){
    set<Id> accids = new set<id>();
    for(Account acc : acclist){
        if(acc.AccountStatus != null && acc.AccountStatus != oldMap.get(acc.id).AccountStatus && acc.AccountStatus == 'Open'){
    List<ContactShare> conShare = [Select id, RowCause from ContactShare where Id In :accids And UserORGroupId = :UserInfo.getUserId()];
    for(ContactShare con : conShare){
        con.RowCause = Schema.ContactShare.RowCause.Manual;
    Update con;
  • Welcome to SFSE! Is your code throwing an error or just not doing anything at all? One thing that I can immediately see that will cause issues with this code is that you're not filtering the ContactShare records to only those where the RowCase is set to Manual. These are the only sharing entries that can be updated as per the ContactShare docs. Could you edit your question and include some more details about the exact issue that you're facing? Jan 14 at 20:29
  • @CallumMacErlich yes its is throwing error that RowCause is not updatable field. I am not able find any other way to resolve issue through Apex sharing,
    – Puja
    Jan 22 at 6:22

1 Answer 1


Your update statement is incorrect. You need to update your conShare list, not `con' which is undefined.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .