I tried this code but I am getting error anyone please help on this:
trigger fillValue on Employee__c (after insert, after update) {
map<decimal,contact> mapcon = new map<decimal,contact>();
list<employee__C> ee = new list<employee__c>();
list<contact> con = [select id,test__c from contact where test__C != null];
if(trigger.isinsert){
for(employee__c emp : trigger.new){
for(contact c :con){
if(emp.test__C == c.test__c){
mapcon.put(c.test__c,c);
}
}
}
for(employee__c eee : trigger.new){
if(mapcon.size()>0){
eee.contact__C = mapcon.get(eee.test__C).id;
}
ee.add(eee);
}
insert ee;
}
}
Error:
Invalid Data. Review all error messages below to correct your data. Apex trigger fillValue caused an unexpected exception, contact your administrator: fillValue: execution of AfterInsert caused by: System.FinalException: Record is read-only: Trigger.fillValue: line 14, column 1