function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ddggddgg 

to make batch apex class to update records

anyone can help me with this batch, the problem is that I'm not finding the records of the entity EventRelation to update the records of the other entity.

 

Thanks,

 

global void execute(Database.BatchableContext BC, List<sObject> scope){
// Create a map for the chunk of records passed into method.
Map<ID, Informe_icex__c> iMap = new Map<ID, Informe_icex__c>((List<Informe_icex__c>)scope);
System.Debug('iMap Records : ' + iMap);

List<EventRelation> eRList = [SELECT Id,response,Status,RelationId,EventId,RespondedDate FROM EventRelation WHERE Id IN
:iMap.keySet()];
System.Debug('EventRelation Records 1 : ' + eRList);

List<Informe_icex__c> listToBeUpdated = new List<Informe_icex__c>();
for(Informe_icex__c i : iMap.values()){
System.Debug('EventRelation Records 2 : ' + eRList);
System.Debug('Informe_Icex Records: ' + i);
if(!eRList.isEmpty()){
i.Comentarios_Invitados__c = eRList[0].response;
i.Estado_Invitado__c = eRList[0].status;
listToBeUpdated.add(i);

}
}
if(listToBeUpdated.size()>0){
update listToBeUpdated;

}

Vadim RudkovVadim Rudkov

iMap.keySet() contains IDs of the Informe_icex__c object, not IDs of the EventRelation object. So [select ... from EventRelation WHERE Id IN
:iMap.keySet()] will return nothing.

sambasamba

You're right.