I need to create a Trigger on a custom object that will update the OpportunitySplit records to reflect the Users and Splits inserted into a custom object.
My logic is:
Get the users and split percentages (3 total users), and the Opportuity Id, from the inserted record on the custom object
Select all existing OpportunityTeamMember records related to the Opportunity
Select all existing OpportunitySplit records related to the Opportunity
Delete all OpportunitySplit records for the given Opportunity except the Opportunity Owners OpportunitySplit record
Delete all OpportunityTeamMember records for the given Opportunity except the Opportunity Owners OpportunityTeamMember record.
Excecute a Database.Upsert that updates the Opportunity Owners TeamMemberRole to a specific value (DM Schedule Split Primary) and inserts new OpportunityTeamMember records for 2 other users.
This works fine
Execute a Database.Upsert that updates the Opportunity Owners SplitPercentage and inserts new OpportunitySplit records for the other 2 users. (The total of all 3 equals 100)
This throws an error: FIELD_INTEGRITY_EXCEPTION, Can't update splits: percentages don't add up to 100.00%
What is the secret here?