• Jesus Ferreras
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 9
    Replies

Hello, 

 

How I can do this assignment correctly?

 

Thanks

 

 

global Database.Querylocator start(Database.BatchableContext bc){
//where fecha_del_evento__c>=LAST_N_DAYS:1
return Database.getQueryLocator([SELECT ID, Comentarios_Invitados__c,EventRelationId__c,Estado_Invitado__c,fecha_del_evento__c FROM Informe_icex__c]);
}

global void execute(Database.BatchableContext BC, List<sObject> scope){

Map<ID, Informe_icex__c> iMap = new Map<ID, Informe_icex__c>((List<Informe_icex__c>)scope);
System.Debug('iMap Records : ' + iMap);

Set<Id> sIdInforme = new Set<Id>();
Informe_icex__c ii;

for(sObject c:scope) {
ii = (Informe_icex__c) c;
if(!sIdInforme.contains(ii.EventRelationId__c))
sIdInforme.add(ii.EventRelationId__c);

}
System.Debug('sIdInforme Records: ' + sIdInforme);


List<Informe_icex__c> listToBeUpdated = new List<Informe_icex__c>();

for(EventRelation er:[SELECT Id,response,Status,RelationId,EventId,RespondedDate FROM EventRelation WHERE Id IN :sIdInforme]){
System.Debug('EventRelation Records er: ' + er);
if (!iMap.containsKey(er.Id)) {
System.Debug('passed through here : ' + iMap);
Informe_icex__c icex = iMap.get(er.Id); //I saw that this assignment is empty, the error is System.NullPointerException: Attempt to de-reference a null object
System.Debug('Icex Records : '+ icex);
if(er.Status!='New'){
System.Debug('Its different from new : ');
icex.Comentarios_Invitados__c = er.response;
icex.Estado_Invitado__c = er.status;
listToBeUpdated.add(icex);

}
}

}
if(listToBeUpdated.size()>0) update listToBeUpdated;
System.Debug('passed through here update : ');
}

I need help. I want to create a batch class to update values from another object. this is my code but it is giving me this error

anyone can help? Thanks.

This is the start and execute section

 

global Database.Querylocator start(Database.BatchableContext bc){
      return Database.getQueryLocator([SELECT ID, Comentarios_Invitados__c,EventRelationId__c,Estado_Invitado__c,fecha_del_evento__c FROM Informe_icex__c where fecha_del_evento__c>=LAST_N_DAYS:1]);
}

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);
        
        List<EventRelation> eRList = [SELECT Id,response,status FROM EventRelation WHERE Id IN
             :iMap.keySet()];
             
        for(Informe_icex__c i : jobMap.values()){
            
            if(!eRList.isEmpty()){
            i.Comentarios_Invitados__c = eRList.response;
            i.Estado_Invitado__c = eRList.status;
            }
        }
        update iMap;
 

}

Hello, 

 

How I can do this assignment correctly?

 

Thanks

 

 

global Database.Querylocator start(Database.BatchableContext bc){
//where fecha_del_evento__c>=LAST_N_DAYS:1
return Database.getQueryLocator([SELECT ID, Comentarios_Invitados__c,EventRelationId__c,Estado_Invitado__c,fecha_del_evento__c FROM Informe_icex__c]);
}

global void execute(Database.BatchableContext BC, List<sObject> scope){

Map<ID, Informe_icex__c> iMap = new Map<ID, Informe_icex__c>((List<Informe_icex__c>)scope);
System.Debug('iMap Records : ' + iMap);

Set<Id> sIdInforme = new Set<Id>();
Informe_icex__c ii;

for(sObject c:scope) {
ii = (Informe_icex__c) c;
if(!sIdInforme.contains(ii.EventRelationId__c))
sIdInforme.add(ii.EventRelationId__c);

}
System.Debug('sIdInforme Records: ' + sIdInforme);


List<Informe_icex__c> listToBeUpdated = new List<Informe_icex__c>();

for(EventRelation er:[SELECT Id,response,Status,RelationId,EventId,RespondedDate FROM EventRelation WHERE Id IN :sIdInforme]){
System.Debug('EventRelation Records er: ' + er);
if (!iMap.containsKey(er.Id)) {
System.Debug('passed through here : ' + iMap);
Informe_icex__c icex = iMap.get(er.Id); //I saw that this assignment is empty, the error is System.NullPointerException: Attempt to de-reference a null object
System.Debug('Icex Records : '+ icex);
if(er.Status!='New'){
System.Debug('Its different from new : ');
icex.Comentarios_Invitados__c = er.response;
icex.Estado_Invitado__c = er.status;
listToBeUpdated.add(icex);

}
}

}
if(listToBeUpdated.size()>0) update listToBeUpdated;
System.Debug('passed through here update : ');
}

I need help. I want to create a batch class to update values from another object. this is my code but it is giving me this error

anyone can help? Thanks.

This is the start and execute section

 

global Database.Querylocator start(Database.BatchableContext bc){
      return Database.getQueryLocator([SELECT ID, Comentarios_Invitados__c,EventRelationId__c,Estado_Invitado__c,fecha_del_evento__c FROM Informe_icex__c where fecha_del_evento__c>=LAST_N_DAYS:1]);
}

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);
        
        List<EventRelation> eRList = [SELECT Id,response,status FROM EventRelation WHERE Id IN
             :iMap.keySet()];
             
        for(Informe_icex__c i : jobMap.values()){
            
            if(!eRList.isEmpty()){
            i.Comentarios_Invitados__c = eRList.response;
            i.Estado_Invitado__c = eRList.status;
            }
        }
        update iMap;
 

}