You need to sign in to do that
Don't have an account?
Trigger not Updating fields
Hi,
I am trying to insert/update the value when the status change to Reviewed it should put the date time in a_date__C and
when status changed to Approved it should put the date time in r_date__C.
But it's not giving me an error neither its' updating the field.
trigger updatefield on imp__c (after update) {
Map<String,imp__c > recordsimp = new Map<String,imp__c >();
List<account> accountToUpdate = new List<account>();
List<imp__c> impToInsert = new List<imp__c>();
if (Trigger.isInsert){
for (imp__c impRecord : trigger.new){
if(imprecord.Status__c == 'Reviewed' || imprecord.Status__c == 'Approved'){
imp__c impObj = new imp__c (a_Date__c = datetime.Now(),r_date__c=datetime.now());
insert impObj;
}
}
insert impToInsert;
}
Else{
for(imp__c impRecord : trigger.new){
Imp__c oldImp = trigger.oldMap.get(impRecord.Id);
// only add IMP record Ids to the Map if the IMP record Status__c field changes
if(impRecord.Status__c != oldImp.Status__c)
recordsimp.put(impRecord.rec_ID__c,impRecord);
}
// only execute below if the Map is not empty (any Status__c changes occured above)
if(!recordsimp.isEmpty(){
accountToUpdate = [select id,Status__c,account_num__c from account where account_num__c IN: recordsimp.keyset()];
for(account accounts: accountToUpdate){
accounts.status__c = recordsimp.get(accounts.account_num__c).Status__c;
}
if(accountToUpdate.size() > 0){
update accountToUpdate;
}
}
}
}
trigger updatefield on imp__c (after update,after insert) in 1st line.
you are missing after insert.
I added after insert but still not updating the field.
try this out:
Source Code:
You can change it:
Thanks,
Samba