You need to sign in to do that
Don't have an account?
Unable to set the contact id for contactShare
I am developing a trigger that will give access to certain contact records
that will meet some criteria. I need to update and insert a ContactShare
object for the same. However I am getting a compilation error
Error: Compile Error: Field is not writeable: ContactShare.ContactId at
line 8 column 9
trigger Share_Contact_For_Account on Contact (after insert, after update) {
for (Contact c : Trigger.new) {
ContactShare cs = new ContactShare();
cs.ContactId = c.Id;
cs.ContactAccessLevel = 'Edit';
}
}
Any one got any ideas as to what I am doing wrong?
thanks,
-Rajiv
Can you set it at construct time? e.g.
The above code also generates the same error. The issue was also reported
in another thread.
http://boards.developerforce.com/t5/General-Development/ContactShare-object-contactId-not-writable/td-p/191637
Is there a solution to this?
thanks,
Rajiv
This is related to your org wide sharing defaults, but the error message isn't that helpful.
I got the same in my dev org, but my sharing settings were that accounts are public read/write and contacts are controlled by parent. This means that everyone already had full access to all contacts, and thus contact sharing rules aren't available.
I changed my contact org wide default to public read only, and was able to save the code without error.
Hi Bob, many thanks buddy. It's working fine now.
thanks,
Rajiv
Dependent class is invalid and needs recompilation: Class ApexBaseClass : Field is not writeable: ContactShare.ContactId
This is FRUSTRATING. Does anyone have a better approach for solving this in a Managed Package?