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
Sachin10Sachin10 

INVALID_CROSS_REFERENCE_KEY, You can't create an Opportunity Split for a user unless they're part of the opportunity team.: [SplitOwnerId]

Hi All,
I'm getting the below error while I try to insert an opportunity split record via apex.
System.DmlException: Upsert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, You can't create an Opportunity Split for a user unless they're part of the opportunity team.: [SplitOwnerId]

I have a trigger on opportunity Team Member which when deactivated the above code works.
Not sure what is the link between the Opportunity Team Member trigger and Opportunity Split creation.

Usually the team member gets automatically added/created while creating a opportunity split record.
But in this case, when opportunity team member trigger is active, It doesn't seem to work.

Any suggestions/pointers are most welcome.
Many thanks in advance
Anil JAdhav 14Anil JAdhav 14
Hi Sachin,
As per your description above, seems you are referencing somethimg that do not have access. Thats why you are getting INVALID_CROSS_REFERENCE_KEY.
Its better to share the code.
Regards,
Anil
Sachin10Sachin10
Hi Anil,
Here is the code:
OpportunityTeamMember Trigger:
trigger opporutnityTeamMemberTrigger on OpportunityTeamMember (before insert) {
    for(opportunityTeamMember otm: trigger.new){
        otm.OpportunityAccessLevel = 'Edit';
    }
}

Code snippet which is causing the error:
OpportunitySplit split = new OpportunitySplit();
                split.SplitOwnerId = '00528000000yB1s';
                split.SplitPercentage = 50;
                split.OpportunityId = '00628000004zNBU';
upsert split;