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
EvanAlterEvanAlter 

Can't create OpportunityShare via API

So I am trying to create an OpportunityShare for every Opportunity in my Salesforce site. However I keep getting errors back.

The first error I got back was:

"Unable to create/update fields: Id. Please check the security settings of this field and verify that it is read/write for your profile." with the status of INVALID_FIELD_FOR_INSERT_UPDATE

I thought this was really strange because I am the admin and I thought I was able to access anything.

So I went to Setup : Security Controls : Sharing Rules and there I noticed that Opportunity Access was set to "Public Read Only". So I changed it to "Public Read/Write" and thought I had finally solved the problem...

Until that is I ran my program again and got a new error which was

"entity type cannot be inserted: EntityObject of type: OpportunityShare, id: " with the status of CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY

My first thought was I screwed up and was giving null IDs but that isn't the case, so right now I am lost. Was the chaning the Sharing Rules really necessary? And how can I get this to work.

Thanks

~Evan Alter
DevAngelDevAngel

Don't include the id field on the create call.

EvanAlterEvanAlter
how do you tell it what Opportunity you are trying to share? I thought the id slot was for the id of the Opportunity. Otherwise aren't I just creating a share of nothing?
DevAngelDevAngel

Every object has an ID field.  This field is not known until the object is created.  When creating an oppty share you will not know the Oppty share id (the id field).  You DO know the OpportunityId which is the field that you need to set to indicate which oppty the share is for.