• Brent Landels
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Trying to create an Apex trigger that updates the Opportunity splits to evenly distribute the percentage of the sale to each Opportunity Team Member. I'm using a split that validates to 100%, and I'm getting this error every time, even though it adds up to 100%.

I was getting an error with the trigger, so I looked up the split records (2 team member, 35% and 65%) that I created manually on the opportunity with a SOQL Query.  I tried editing the individual split records to 100 and 0 percent. I get the following error when I click Save Rows. This was the same error I was getting in my trigger.

User-added image

​​​​​​​Thanks for your help!

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?