You need to sign in to do that
Don't have an account?
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?
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;
}
}
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 .
OpportunitySplit oppSplit = new OpportunitySplit();
oppSplit.OpportunityId = opp.Id;
oppSplit.SplitOwnerId = [User Variable];
oppSplit.SplitTypeId = '1490m000000CaVKAA0';
oppSplit.SplitPercentage = 50.0;
splitRecords.add(oppSplit);
}
if(!splitRecords.isEmpty()) {
insert splitRecords;
}
This Split is a team member split that should take 50% of the Owner's split. Salesforce calculates this 50% reduction natively, when this is entered via the UI, but gives us this error when run via Apex: caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Can't update splits: percentages don't add up to 100.00%.: