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
PaulDysonPaulDyson 

Can't write to RowCause when running a test

This is strange ...

 

I'm trying to test some custom sharing code. Manually the code all works fine. However, when I run it under test, I get a System.SObjectException: Field is not writeable: Chatroom__Share.RowCause exception.

 

The code is running without sharing so it shouldn't be anything to do with the permissions of the user (although I've manually tested using the same profile as the test user used in the runAs() method).

 

Any ideas? 

Abhinav GuptaAbhinav Gupta

Seems you are updating the Chatroom__Share record and including the RowCause field in the update too : Chatroom__Share.RowCause. RowCause field is not updateable once the record is created. If you need to change it, delete the previous Chatroom__Share record and create new one.

 

More detailed synopsis here : http://www.tgerm.com/2012/01/field-is-not-writeable-sharerowcause.html