5

I am facing trouble while inserting 1 share record. When I am loggin to Admin Profile, it is working fine without any DML exception, but when I am login to Sales profile, then I am facing such exception.

I checked with DescriveSObject isCreatable() method, I can see that Sales profile has create access on Package_Share__c object.

This is the list I am inserting:

packageShareInsertList : (Package__Share:{UserOrGroupId=00540000000zHI5AAM, ParentId=a1I560000004iRIEAY, RowCause=PKG_Sales_Team__c, AccessLevel=Edit})

This is th DML Exception I am facing:

04:21:17.791 (3215279840)|FATAL_ERROR|System.AssertException: Assertion Failed: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, invalid row cause: []:

But Row cause has valid value that I am sure. If it was a wrong value, then other profiles would have thrown the same issue.

Please advise.

  • I guess its a custom apex sharing reason – Prajith Feb 26 '16 at 9:56
  • 1
    Use RowCause = Schema.Package_Share__c.RowCause.PKG_Sales_Team__c, assuming the object name is Package_Share__c – Prajith Feb 26 '16 at 9:57
  • @Stygon : yes, RowCause=PKG_Sales_Team__c. PKG_Sales_Team__c is the custom Apex sharing reason on Package__c custom object. – SFDC Geek Feb 26 '16 at 9:58
  • The way you are assigning rowcause in ur code is wrong, please do so as RowCause = Schema.Package__Share.RowCause.PKG_Sales_Team__c – Prajith Feb 26 '16 at 10:04
  • 1
    @Stygon : I dont think so that is the reason. I have tested with your solution, same issue is happening. Schema.Package__Share.RowCause.PKG_Sales_Team__c gives you string value and RowCause data type is string, so I think we can assign that way too. If assigning value was wring, then how it i sworking for Admin profile. – SFDC Geek Feb 26 '16 at 10:10
6

I believe you are having the issues because the user you are trying does not have "Modify all data" permission.

According to the documentation LINK

Apex managed sharing enables developers to pro-grammatically manipulate sharing to support their application’s behavior through Apex or the SOAP API. This type of sharing is similar to Force.com managed sharing. Only users with “Modify All Data” permission can add or change Apex managed sharing on a record. Apex managed sharing is maintained across record owner changes.

I came across another answer where this was successfully achieved via changing class's sharing model as "without sharing". Please try doing that as well.

Link to the Answer


EDIT

I believe you received error using with sharing because a user requires at-least read access to the record for which the share is to be created. LINK

If a trigger changes the owner of a record, the running user must have read access to the new owner’s user record if the trigger is started through the following:

  • With Sharing was the issue here. I have changed my class back to without sharing and it worked like charm. Thanx:) – SFDC Geek Feb 26 '16 at 13:05
  • I had the same issue with this. Normally, triggers operate in the "System Context", so I don't see why this operation should generate an error for classes that are "with sharing". However, I was able to get it to work by removing "with sharing" entirely - thus letting the class inherit the sharing mode from the calling trigger. – Force2b_Mike Feb 9 '17 at 15:01

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.