I have List<Id> topTenGameIds and List<Game__c> with ids from List<Id>
List<Id> topTenGameIds = new List<Id>();
for(AggregateResult gameRecord: res) {
topTenGameIds.add((Id)gameRecord.get('gameId'));
}
List<Game__c> topGames = [SELECT Id, TotalMoneyBet__c, GameRating__c
FROM Game__c
WHERE Id IN :topTenGameIds];
Question is: how to set TotalMoneyBet__c that its equals topTenGameIds index?
If you want to set the TotalMoneyBet__c field of each Game__c record in the topGames list to be equal to the index of that record in the topTenGameIds list, you can do so in a loop. Here's a sample of how you can achieve this:
Besides I made these calculations to calculate the bonuses from this source https://casinosanalyzer.com/bonuses-by-countries/poland-pol , by the way it is very convenient, because here I found all the current bonuses for Poland, this amazed me, because until now I had to look for them all separately, and here they are gathered together and it is much easier to create a statistic.List<Id> topTenGameIds = new List<Id>();
for (AggregateResult gameRecord : res) {
topTenGameIds.add((Id)gameRecord.get('gameId'));
}
List<Game__c> topGames = [SELECT Id, TotalMoneyBet__c, GameRating__c
FROM Game__c
WHERE Id IN :topTenGameIds];
// Check if the size of topGames and topTenGameIds lists match
if (topGames.size() == topTenGameIds.size()) {
for (Integer i = 0; i < topGames.size(); i++) {
// Set TotalMoneyBet__c of each Game__c record to its index in topTenGameIds
topGames[i].TotalMoneyBet__c = i;
}
// Update the records
update topGames;
} else {
// Handle the case where the lists don't match in size.
// You may want to log an error or take appropriate action.
}