3

I have an org that was recently updated to API 32, which broke some triggers that create Sharing Records. This code worked previously to the update to API 32.

public void OnAfterObjectInsert(List<Object__c> insertRecords) {
  List<Object__Share> newShares = new List<Object__Share>();
  List<AccountShare> clientShares = [SELECT Id,AccountId,RowCause,UserOrGroupId FROM AccountShare WHERE AccountId = :insertRecords[0].Client__c];
  for (AccountShare cs : clientShares) {
    if(cs.UserOrGroupId != Userinfo.getUserId()) {
      Object__Share curShare    = new Object__Share();
      curShare.ParentId         = insertRecords[0].id;
      curShare.RowCause         = 'Test__c'; //or Schema.Object__Share.RowCause.Test__c;
      curShare.UserOrGroupId    = cs.UserOrGroupId;
      curShare.AccessLevel      = 'Edit';
      newShares.add(curShare);
    }
  }
  insert newShares;
}

This is returning a DML exception. The reported error is "invalid row cause." Using Manual as the RowCause works, and interestingly inserting a record with workbench.developerforce.com with Test__c as a RowCause works as well. I've also set the api of the relevant class to 32, which had no effect. Any help is appreciated.

1
  • 1
    Is Test__c a valid RowCause? They may have added some validation that you can only use a custom cause if it exists. – Adrian Larson Oct 23 '14 at 23:03
5

I faced and same issue today and my solution may work in this case.

What I did is, removed "with sharing" from class and worked fine. I think when we use with sharing, user doesn't have access to add the manual sharing.

1
  • Yes in general your classes that manipulate sharing should be run without sharing because most users don't have rights on them. – Adrian Larson Jan 22 '15 at 19:10

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.