I recently came across a rather interesting syntax of a map in a batch apex which I would be grateful if anyone can explain to me how it's actually working:
global class CommissionSharingRecalc implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC){
return Database.getQueryLocator([SELECT Id, Commission_Approver__c, Payee__c
FROM Commission__c]);
}
// The executeBatch method is called for each chunk of records returned from start.
global void execute(Database.BatchableContext BC, List<sObject> scope){
// Create a map for the chunk of records passed into method.
Map<ID, Commission__c> commissionMap = new Map<ID, Commission__c>((List<Commission__c>)scope);
}
}
My curiosity is on this part of the code:
Map<ID, Commission__c> commissionMap = new Map<ID, Commission__c>((List<Commission__c>)scope);
How is the id key and Commision__c values being passed into the Map without the map add method. Thanks for the responses.