- I have an object called log__c in that fields have Description__c, Action__c(label name :Title)
- Lookup with Contact object, when I change the phone field of contact the object then in log__c object with Description__c field should be inserted that old phone is 123 and new phone 456 like this my requirement.
I have tried this code but is updating multiple times with check and the Description field is empty, In Description, I need to show old and new values which changed respectively.
trigger oldvalue on Contact (after insert,after update) {
Set<Id> lstLogId = new Set<Id>();
String OlpPhone;
String NewPhone;
list<Log__c> logtimeUpdate = new list<Log__c>();
if(trigger.IsAfter && (trigger.IsUpdate || trigger.IsInsert)){
for(Contact Con : trigger.new ){
if(con.Phone != Trigger.oldMap.get(con.Id).Phone){
OlpPhone = Trigger.oldMap.get(con.Id).Phone;
NewPhone = con.Phone;
lstLogId.Add(Con.Id);
}
}
}
list<Log__c> logtime = [Select id,Name,Contact ,Description__c,Action__c FROM Log__c Where Contact In:lstLogId ];
For(Log__c l : logtime){
l.Action__c ='check';
l.Description__c ='\n phone number old value ='+OlpPhone+ ' New Phone = ' + NewPhone;
logtimeUpdate.Add(l);
}
update logtimeUpdate;
}
Error