+ Start a Discussion
shawthornerrshawthornerr 

FIELD_INTEGRITY_EXCEPTION, Can't update splits: percentages don't add up to 100.00%

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?

jappenzeller2jappenzeller2
Did you ever figure this out? I am having a similar issue. 
Victor DeLimaVictor DeLima
Having same problem. Any help would be appreciated!
archita.chakrabortyarchita.chakraborty
I am also facing the same issue. Has anybody found solution for this 
Pratibha Pandit 7Pratibha Pandit 7
I am also facing the same issue. Has anybody found solution for this ??
Pratibha Pandit 7Pratibha Pandit 7
Below is my code: I am calling it via trigger(After insert, After Update)
I am creating Opportunity Split automatically when Team Member with role 'MRVL' is getting added. I need to split the team members equally which will be divided among them in 25% of share, becuase 75% should be for opportunity owner. But i am getting error:

Upsert failed. First exception on row 1 with id 0496C000000K2xDQAS; first error: FIELD_INTEGRITY_EXCEPTION, Can't update splits: percentages don't add up to 100.00%.: []: Class.Opportunitysplithandler.opptysplit: line 35, column 1  

Please Help: If my logic is wrong...


public class Opportunitysplithandler {    
    public static void opptysplit(Map<Id,OpportunityTeamMember> oppty){
        
        List<OpportunityTeamMember> oppteam = new List<OpportunityTeamMember>() ;
        List<OpportunitySplit> oppSplit = new List<OpportunitySplit>();
        set<Id> oppId = new Set<Id>();
        
        For(OpportunityTeamMember OTM : oppty.values()){
            if (OTM.TeamMemberRole.contains('MRVL')){
                oppteam.add(OTM);  
                oppId.add(OTM.OpportunityId);
            }               
        }        
           
        List<OpportunitySplit> oppSpl = [select Id, opportunityId  from OpportunitySplit where opportunityId In :oppId];
        system.debug('Pratibha here'+oppteam);
        
        if(oppteam.size() >0){
            Decimal percentageShare = 25/(oppteam.size()+oppSpl.size()); //this will calculate the %age share for each team member
            for(OpportunityTeamMember newotm : oppteam){
                OpportunitySplit os = new OpportunitySplit();
                os.OpportunityId = newotm.opportunityId ; 
                os.SplitOwnerId = newotm.UserId;
                os.SplitPercentage = percentageShare;
                oppSplit.add(os);
            }       
            
        }
        for(OpportunitySplit old : oppSpl){
            
                Decimal percentageShare = 25/(oppteam.size()+oppSpl.size());
                old.SplitPercentage = percentageShare;
                oppSplit.add(old);
        }
                
        upsert oppSplit;
    }
    
    
}
SFDC LabsSFDC Labs
am also facing same issue. Any fix ?
anil s 25anil s 25

Hi SFDC Labs ,

Can you please elaborate on the exact issue ,i might help you .Even i faced the similar kind of issue and have overcome .

Did you write trigger on opportunity or opportunity split trigger .