I have to update bulk records by apex class which is called from an apex trigger. Please find my class and trigger below. Batch class:
global class UpdateAccountArea implements Database.Batchable<sObject> {
Map<Id,Id> updatedHCPMap = new Map<Id,Id>();
global UpdateAccountArea(Map<Id,Id> updatedMap) {
updatedHCPMap = updatedMap;
}
global Database.QueryLocator start(Database.BatchableContext BC) {
return DataBase.getQueryLocator([SELECT Id,Depth_Account__c
FROM HCP_Depth_Tracker_OAPI__c
WHERE Depth_Tracker_OAPI__c IN : updatedHCPMap.keySet()]);
}
global void execute(Database.BatchableContext BC,List<HCP_Depth_Tracker_OAPI__c> scopeAcc) {
for (Integer i=0;i<scopeAcc.size();i++){
scopeAcc.get(i).Depth_Account__c=updatedHCPMap.get(scopeAcc.get(i).Depth_Tracker_OAPI__c).Account_oapi__c;
}
update scopeAcc;
}
global void finish(Database.BatchableContext BC) {
}
}
Apex trigger:
trigger HCPREFERENCE2 on Depth_Tracker_OAPI__c (after insert,after update) {
List<HCP_Depth_Tracker_OAPI__c> updateTaskList = new List<HCP_Depth_Tracker_OAPI__c>();
List<HCP_Depth_Tracker_OAPI__c> TaskList = new List<HCP_Depth_Tracker_OAPI__c>();
Map<Id,Id> updatedMap = new Map<Id,Id>();
for (Integer i=0;i<Trigger.new.size();i++) {
Database.executeBatch(new UpdateAccountArea(updatedMap ));
}
}
I am getting below error here in the class.
Error: Compile Error: Initial term of field expression must be a concrete SObject: Id at line 17 column 91
Can someone help me here?