You need to sign in to do that
Don't have an account?
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.
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
bShr.RowCause = 'Project Team' ;