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
Jesus FerrerasJesus Ferreras 

Save error: Initial term of field expression must be a concrete SObject: LIST<EventRelation>

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;
 

}

souvik9086souvik9086

Hello, there are some problems in the code

 

iMap.keySet() this contains the id of Informe_icex__c object.

 

But you are fetching EventRelation from that id.

List<EventRelation> eRList = [SELECT Id,response,status FROM EventRelation WHERE Id IN
:iMap.keySet()];

 

Again you are assigning value from a list directly like

i.Comentarios_Invitados__c = eRList.response;

 

Either you do eRList.get(0) or use loop to get it covered.

 

And also before updating do this

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

then in loop after assigning do like this

listToBeUpdated.add(i);

 Outside loop

if(listToBeUpdated.size()>0){

update listToBeUpdated;

}

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

Jesus FerrerasJesus Ferreras

Hello souvik9086

I made the changes but have this error 'Save error: Variable does not exist: listToBeUpdated'

 

List<EventRelation> eRList = [SELECT Id,response,status FROM EventRelation WHERE Id IN
             :iMap.keySet()];
       
             
        for(Informe_icex__c i : jobMap.values()){
            List<Informe_icex__c> listToBeUpdated = new List<Informe_icex__c>();
            if(!eRList.isEmpty()){
            i.Comentarios_Invitados__c = eRList.response;
            i.Estado_Invitado__c = eRList.status;
            listToBeUpdated.add(i);
            }
        }
        if(listToBeUpdated.size()>0){
        update listToBeUpdated; //the error is Save error: Variable does not exist: listToBeUpdated
}

}

 

I can do, can help

Thanks,

souvik9086souvik9086

You have to declare the list variable before the for loop like this

 

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

 

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

 

 

Jesus FerrerasJesus Ferreras

in this case I have this error 'Save error: Initial term of field expression must be a concrete SObject: LIST<EventRelation>'  the original error

 

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()];
       
        List<Informe_icex__c> listToBeUpdated = new List<Informe_icex__c>();      
        for(Informe_icex__c i : jobMap.values()){
            if(!eRList.isEmpty()){
            i.Comentarios_Invitados__c = eRList.response;
            i.Estado_Invitado__c = eRList.status;
            listToBeUpdated.add(i);
        
            }
        }
        if(listToBeUpdated.size()>0){
        update listToBeUpdated;
}

}      

souvik9086souvik9086

I mentioned that in my first post that

 

"Again you are assigning value from a list directly like

i.Comentarios_Invitados__c = eRList.response;

 

Either you do eRList.get(0) or use loop to get it covered."

 


You have to use that one value not the list.

 

If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.

Thanks

Avidev9Avidev9

There are several basic mistake in your code.

 

Map<ID, Informe_icex__c> iMap = new Map<ID, Informe_icex__c>((List<Informe_icex__c>)scope);
        

//In the below query you are comparing EventRelation's Id with Informer_icex__c Id and they will never match and hence this wont return any value

        List<EventRelation> eRList = [SELECT Id,response,status FROM EventRelation WHERE Id IN
             :iMap.keySet()];
       
        List<Informe_icex__c> listToBeUpdated = new List<Informe_icex__c>();      
        for(Informe_icex__c i : jobMap.values()){
            if(!eRList.isEmpty()){
//in the below lines : You cannot assign a list to field, where erList is a list and you can access fields of a single object not a list i.Comentarios_Invitados__c = eRList.response; i.Estado_Invitado__c = eRList.status; listToBeUpdated.add(i); } } if(listToBeUpdated.size()>0){ update listToBeUpdated; } }

 

Jesus FerrerasJesus Ferreras

Hello is true, I saw that the ErList list is empty,

what is the correct syntax, I am beginner in that, can you help me?

 

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

 

 

Thanks,

Jesus FerrerasJesus Ferreras

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 entity Informe_icex.

 

Thanks

 

 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); // the results is empty
       
        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;
        
}

Avidev9Avidev9
Can you describe .. what exactly is your requirement ?
Jesus FerrerasJesus Ferreras

Hello Avidec9,

the problem is that I'm not finding the records of the entity EventRelation to update the records of the entity Informe_icex,

 

I think that my error is the red line, because the result of this list is empty.

 

 

 

global class Actualizar_informe implements Database.Batchable<sObject>,Database.stateful
{
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){
       // 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;
        
}

}     

Avidev9Avidev9
I already pointed that in last post. But what is your exact requirement ?