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
NenzNenz 

ContactShare object contactId not writable???

 

The below yields Error: Compile Error: Field is not writeable: ContactShare.ContactId at line 5 column 21   This error message must be something different then what it's telling me.

How / Why is contactID not writable?

 

Just a quick example....  all comments on bad coding practices of not bulk enabling the trigger and hardcoding an id aside.. :)

 

 

trigger ContactCheckReferral on Contact (after insert ) {   
            for (Contact c : Trigger.new) {
                if(c.Consent_to_participate_in_network__c) {
                    ContactShare cs = new ContactShare();
                    cs.ContactId = cs.id;
                    cs.UserOrGroupId = '00GS0000000Ub0mMAC';
                    insert cs;
                }                           
            }
}

 

 

yudhvirmoryudhvirmor

Contact Id, Account ID, Opportunity ID etc are unique Ids assiged to each record by Salesforce. Its a system field so you can't overwrite it.

NenzNenz

I understand that ContactId is auto assigned on the Contact Object.. Opp ID is auto assigned on the Opportunity object..  I'm writing to the ContactShare Object.. I have a contact and I want to manually share this contact  I have the contactID i want to insert it into ContactShare How does contactshare know what ID to assign if I don't tell it?  ie.. How does it know what contact I'm attempting to share via code..   This can't be correct I've seen code snippets that do exactly that. for example http://blog.jeffdouglas.com/2009/11/25/programmatically-creating-sharing-rules-with-apex/

 

sara_csara_c

We are having the same problem - did you ever figure out a programmatic workaround?

 

Thanks!

Sara

Leandro Santillan 6Leandro Santillan 6
Same here, does anyone know why?