1

This is the error

Compile Error: Initial term of field expression must be a concrete SObject: List at line 15 column 18

line 15 was: con1.email = prenew.Changed_Email__c;

trigger updateEmpEmail on Public_Register_Employee__c (after insert, after update) {
List <Public_Register_Employee__c> preNew = new List<Public_Register_Employee__c >(); 

SET <Id> newset = new SET <Id>();


    for(Public_Register_Employee__c pre : Trigger.new){
        newset.add(pre.id__c);   
        preNew.add(pre);  
        }

    for(Contact con1 :[Select Id, email, name, sss_no__c FROM Contact Where Id =: newset]){
    system.assertEquals(con1+'','test');
    con1.ESS_User__c = true;
    con1.email = prenew.Changed_Email__c;
    }


}
  • here prenew is list you need to use like prenew[0] for first record.. or create a map with pre.id__c and Public_Register_Employee__c then use that map in another loop – Ratan Paul Apr 18 '16 at 6:19
  • is there any way without using map? – sfdclearner Apr 18 '16 at 6:22
1

Try using map just store contactId to Public Register employee record

check below code and try to understand..

trigger updateEmpEmail on Public_Register_Employee__c (after insert, after update) {

    // map to hold the contactId to Public Register employee record
    map<Id, Public_Register_Employee__c> mapContactIdToPublicRegisterEmp = new map<Id, Public_Register_Employee__c>();

    for(Public_Register_Employee__c pre : Trigger.new){
        mapContactIdToPublicRegisterEmp.put(pre.id__c, pre);
    }
    List<contact> lstContact = [Select Id, email, name, sss_no__c 
                        FROM Contact 
                       Where Id IN: mapContactIdToPublicRegisterEmp.keySet()];
    for(Contact con1 :lstContact){
    con1.ESS_User__c = true;
    //based on contact Id get the Public Register employee record's changed email value
    con1.email = mapContactIdToPublicRegisterEmp.get(con1.Id).Changed_Email__c;
    }
    update lstContact;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.