Was wondering if there is way to assign the Sharing Reason aka Rowcause Dynamically. Well tried to implement using this "Schema.MyCustomObject__Share.rowCause.My_Sharing_Reason__c" but here I have to fix the sObject and the reason. Is there anyway to assign them dynamically?


You can't assign them completely dynamically.

You need to create them from the point and click interface (Setup->Create->Object Name->Apex Sharing Reasons) or via the meta-data api.

myObject__share share = new myObject__share();
  • Created One Sharing Reason with Label "Test Reason" and am using the above code only. I am Getting the following error : Row Cause: bad value for restricted picklist field: Test Reason;getStatusCode=INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST – Avidev9 Oct 3 '12 at 19:39
  • 1
    Sounds like your entering it with a space in the label. The label should have underscores, or no spaces. So maybe something like: TestReason__c or Test_Reason__c – jordan.baucke Oct 3 '12 at 19:40
  • 1
    Well sorry forgot to reply, Rowcause should be the API name for the Apex Sharing Reason. – Avidev9 Nov 27 '12 at 13:33

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.