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
BuggaBugga 

Rowcause in a formulae field to be used in a trigger

I've defined apex sharing reasons on a custom object, depending a certain feild value there is a formula feild which is storing the value of the rowcase in this format Schema.XXXXXX__Share.RowCause.MySharing__c

I want to use this directly in the after insert trigger. 

                       bShr.ParentId = relid;
                        bShr.UserOrGroupId = bui.Expert_Name__c;
                        bShr.RowCause = bui.Rowcause__c;                                                                          ------- Doesnt work even if the same value is stored
                        //bShr.RowCause = Schema.
XXXXXX__Share.RowCause.MySharing__c; ------ Works fine 
                        bShare.add(bShr)

Could you please suggest if i am doing anything wrong here or suggest any other way ? I need to use different sharing reasons which is calculated in the formulae feild. I can get that to the trigger but that is my last option.

Please let me know.

 

 

Vinita_SFDCVinita_SFDC
Hi,

The way you are refferring is syntatctically incorrect. The only way to reference apex sharing is:

Schema.CustomObject__Share.rowCause.SharingReason__c

If you wish to assign it dynamically the try:

myObject__share share = new myObject__share();
share.put('RowCause','APIOfMyApexSharingReason__c');
share.put('ParentId','...');

Refer: https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_bulk_sharing_creating_with_apex.htm
Biswadeep GhoshBiswadeep Ghosh
Thanks Vinita but i found a way to do it ... Just put the Row cause name as if its a value and it works fine :) 

bShr.RowCause = 'Project Team' ;