+ Start a Discussion
Force.comForce.com 

Unable to set the contact id for contactShare

Hello,

 

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';


    }
}

 

 Thanks

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

BomanBoman

Change line#8 to:

 

 

cs.Id = c.Id;
SSRS2SSRS2

You cannot do it because contactShare.contactId is not writable.To clarify this try following examples.

Not working(Not Editablr)

 

<apex:page standardController="contactShare">
  <apex:form>
    <apex:inputfield value="{!contactShare.contactId}"/>
    <apex:inputfield value="{!contactShare.ContactAccessLevel }"/>
    <apex:commandButton value="save" action="{!save}"/>
  </apex:form>
</apex:page>

 but following working(Editable)

 

<apex:page standardController="opportunity">
  <apex:form>
    <apex:inputfield value="{!opportunity.AccountId}"/>
    <apex:commandButton value="save" action="{!save}"/>
  </apex:form>
</apex:page>

Note:

sforce_api_objects_contactshare.htm

ContactShare object contactId not writable???

-Suresh