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
e r i c.ax249e r i c.ax249 

Can't set RowCause field on custom object's sharing object?

We have a custom object and a sharing object for the custom object.  Via an Apex trigger, we are trying to give users access to records based on certain conditions.  This works fine.  The problem is identifying these records that were inserted via the trigger.  We set up an Apex sharing reason called "MAFTest" and we are setting the new record to that sharing reason in the Apex code:

 

apexShare.RowCause = Schema.Personal_Data__Share.rowCause.MAFTest__c;

But when the sharing record is created, the RowCause is always set to "Manual".   Am I missing something?  I verified via the System Log that "Personal_Data__Share.rowCause.MAFTest__c" evaluates to "MAFTest__c", but it still gets saved as "Manual".

 

Any help is greatly appreciated.

Best Answer chosen by Admin (Salesforce Developers) 
A_SmithA_Smith

Hi Eric,

 

On the code where you are having the issue, edit the class/trigger and change the API version setting to something like 14.0.  Then give it a try.  Earlier versions of the API don't support Apex Sharing Reasons, so you have to be using a later version to get access to them.  I suspect that will fix your issue.

 

Thanks,

Andrew 

All Answers

e r i c.ax249e r i c.ax249

Here's the rest of the code that's in a for loop where I am setting the field values for the sharing record that gets created:

 

// Instantiate the sharing objects apexShare = new Personal_Data__Share(); // Set the ID of record being shared apexShare.ParentId = personalData.Id; //Set the user id of the user who is being granted access apexShare.UserOrGroupId = userClass.User__r.Id; // Set the access level apexShare.AccessLevel = 'read'; // Set the Apex sharing reason apexShare.RowCause = Schema.Personal_Data__Share.rowCause.MAFTest__c; // Add objects to list for insert personalDataShrs.add(apexShare);

 

A_SmithA_Smith

Hi Eric,

 

Are you still having issues with this?  If so, can you post your organization's Id (found under the company profile) so that I may take a look?  You can also send me a private message if you'd rather not post the information.

 

Thanks,

e r i c.ax249e r i c.ax249

I tried it in our Dev Sandbox and it works properly.  It does not work in the Developer account that we were prototyping the project in.  I will pm you the org Id of the Developer account in case you want to look into it.

 

Thanks,

Eric

Message Edited by e r i c on 04-06-2009 06:02 AM
A_SmithA_Smith

Hi Eric,

 

On the code where you are having the issue, edit the class/trigger and change the API version setting to something like 14.0.  Then give it a try.  Earlier versions of the API don't support Apex Sharing Reasons, so you have to be using a later version to get access to them.  I suspect that will fix your issue.

 

Thanks,

Andrew 

This was selected as the best answer
e r i c.ax249e r i c.ax249

You are correct.  The trigger was created by a coworker in his Developer account and he used 12.0.  When I created the trigger in the Sandbox Dev, I used 15.0. 

 

Thanks for your help.