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
Pere Martí RuizPere Martí Ruiz 

Sharing Rule crashing (on creation) when trying to set the RowCause

Hello,

 

I am creating the Sharing rules for several Objects via apex code, until recently our development has worked wihtout any issues but we recently updated some of the users to use the 

Salesforce Platform license (previously they had Saleforce license)

 

I have seen that the field SOBject__Share.RowCause can't be updated (as explains perfectly this post: http://www.tgerm.com/2012/01/field-is-not-writeable-sharerowcause.html) but, this can't be the issue because the sharing rules is being created at that moment (plus previously was working without problem).

 

Here you can see the code piece where the sharing rules is created:

 

Flight_Leg__Share sharingRule = newFlight_Leg__Share();
sharingRule.parentId = fleg.Id;
sharingRule.UserOrGroupId = sharingGroupId;
sharingRule.accessLevel = accessLevel;
sharingRule.RowCause = Schema.Flight_Leg__Share.RowCause.AutoCalculatedRule__c;   

insert sharingRule;

 

 

The code is crashing in the 5th line:  sharingRule.RowCause = ...

The user has read, edit and write permission for that object and all the classes involved are at least version 27.0. If I comment the line were RowCause is assigned everything works flawlessly.

 

My only guess is that there is some kind of restriction for RowCause with the new license Salesforce platform. Can anybody confirm this?

 

Thanks in advance!

 

 

crop1645crop1645

Pere:

 

From the doc, a Platform License is:

Designed for users who need access to custom apps but not to standard CRM functionality. Users with this user license are entitled to use custom apps developed in your organization or installed from Force.com AppExchange. In addition, they are entitled to use core platform functionality such as accounts, contacts, reports, dashboards, documents, and custom tabs. However, these users are not entitled to some user permissions and standard apps, including standard tabs and objects such as forecasts and opportunities. Users with this license can also use Connect Offline.

the simple way to confirm this for user-managed sharing (record at a time) would be to login as a user with a Platform License and see if the Sharing button is available on a detail page 

Pere Martí RuizPere Martí Ruiz

Thanks for the suggestion Eric.

 

I tried what you told me and I have reached the same result both "manually" (logging in as the Salesforce Platform user)  and using apex code:

 

In both cases I can create sharing rules for the User with a Salesforce Platform license but I can't give a Sharing Reason to it.

When doing it manually (logged in as the Salesforce Platform user)  I don't even see the "Reason" field when creating a new sharing rule.

 

On the other hand, if I do the same with a User  with "Salesforce" License there is no problem.

 

 

So I think I can conclude that for Salesforce Platform Licenses the Sharing Reason is not active and we can't use give it any value other than the default.