+ Start a Discussion
Kr ramKr ram 

when date field is made null --update the same field with the previous date value if populated

Hello Gurus,

 

I have a standard object

Scenario:i need to update a contract date__c  custom field on the same object only if the date value is made NULL by external integration  with the previous date value from the same field  if populated,and if previous DATE value is NULL do nothing

 

i know a trigger.old and getmap (id) could be used but i need the exact "after update" trigger syntax,

 

i used this but i get an after update stack  error,

please note i need an after update trigger

 

trigger abc_123 on Asset (after update) {

for (Asset asse : Trigger.new) {

Asset oldAsset = Trigger.oldMap.get(asse.ID);

if ( asse.contract_Date__c==null) {

asse..contract__c = oldAsset..contract_Date__c;

}
}

 

i know this is simple but my brain cells are out on a friday evening,any input appreciated. thank you!

Tim BarsottiTim Barsotti

This should be before update.

 

trigger abc_123 on Asset (before update) {
     for (Asset asse : Trigger.new) {
          Asset oldAsset = Trigger.oldMap.get(asse.ID);
          if (asse.contract_Date__c==null && oldAsset.contract_Date__c != null) {
                asse.contract__c = oldAsset.contract_Date__c;
     }
}