How to fix insufficient access rights on cross-reference id?
I am getting the error:
INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY, insufficient access rights on cross-reference id: [] Scenario is, I am inserting an Opportunity and then Opportunity Line Item from a VisualForce page using controller. When I am doing this I am logged in as user whose profile license is "Authenticated Website".
Strange thing is, when on another org logged in as user whose user profile license is Customer Portal Manager the same code work fine. Both orgs have Opportunity OWD "Read Only" and Opportunity line item "Controlled By Parent". To resolve this problem I've used "without sharing" on class which executes the insertion code, and it works fine from "Authenticated Website" user.
As this may be a security issue when we try to list the app on AppExchange, is there any other way to resolve this problem?
You can check the Object access for the Profile. The error “insufficient access rights on cross reference id.” is thrown when you try to insert/update something that logically cannot be inserted/updated. Some examples: You try to update a record that does not exist. Maybe the record was never there or it was deleted. You try to update an object field that cannot be set explicitly.
These fields can only be updated by the implicitly. e.g.: object owner, CreatedById, CreatedDate, LastActivityDate, LastModifiedById, LastModifiedDate. You cannot explicitly update these fields.
You are trying to give permission to someone but you yourself do not have permission for this. If you are trying to share "Record X" with "User Y" and you yourself do not have access to "Record x", this error happens Or if the "User Y" already has access to it. These are just a few reasons you can get the salesforce error INSUFFICIENT_ACCESS_ON_CROSS_REFERENCE_ENTITY; I am sure there are others.