Skip to content

Commit

Permalink
Update RollupService.cls
Browse files Browse the repository at this point in the history
Bug fix for case when masterRecords contains more than 10 chunks:
SFDO-Community#58
  • Loading branch information
lukeadair committed Jan 7, 2015
1 parent c0c2bc9 commit 14703ad
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion rolluptool/src/classes/RollupService.cls
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,20 @@ global with sharing class RollupService

public virtual List<Database.Saveresult> updateRecords(boolean allOrNothing)
{
// sort (selection sort) masterRecords to avoid having more than 10 chunks in a single database operation
// masterRecords.sort() will not work
Integer indexOfMin;
for( Integer outerIndex = 0; outerIndex < masterRecords.size(); outerIndex++ ){
indexOfMin = outerIndex;
for( Integer innerIndex = outerIndex; innerIndex < masterRecords.size(); innerIndex++ ){
if( String.valueOf(masterRecords.get(indexOfMin).getSObjectType()).compareTo( String.valueOf(masterRecords.get(innerIndex).getSObjectType()) ) > 0 ){
indexOfMin = innerIndex;
}
}
SObject temp = masterRecords.get(outerIndex);
masterRecords.set( outerIndex, masterRecords.get(indexOfMin) );
masterRecords.set(indexOfMin, temp);
}
return Database.update(masterRecords, allOrNothing);
}
}
Expand All @@ -625,4 +639,4 @@ global with sharing class RollupService
public override List<Database.Saveresult> updateRecords(boolean allOrNothing)
{ return super.updateRecords(allOrNothing); }
}
}
}

1 comment on commit 14703ad

@lukeadair
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.