i have trigger on custom child object seasonAddress and it has Masterdetail relationship with contact object. if current season address record is marked as invalid, parent contact record is get updated with the address fields of earlier valid address field values of contact. So i need get the old version of contact records in 'before update trigger' on seasonaddress object.. how can we achive this please help me..

  • How are you marking the address as invalid, programmatically or manually? Apr 11, 2016 at 21:01
  • manually.. we have a checkbox in seasonaddress object.. if user select that checkbox, address become invalid then system automatically updates the address fileds in contact with its previous addressfileds(Assuming previous address fileds are valid)..
    – user30563
    Apr 12, 2016 at 1:24
  • That's what I assumed. See my answer below. Apr 12, 2016 at 4:31

2 Answers 2


Assuming you're manually determining whether the address is valid or not, you'd need to fire a trigger based on a "invalid address" flag on the Contact record and access the Contact__Histories object to access the previous value of that field.

This is of course assuming that you are tracking the history of that field on the Contact object.

So, to Summarize, you need to make sure you're tracking the field history of the address field on the Contact object and then fire your trigger on the "Address is invalid" action and query Contact__Histories and loop over that collection to get the most recent address value and then update your Contact record with that address.


In the update context, you can access the




system variables to get the fields from the object before the update occurs. An example of using this is

for (SObject s: trigger.new){
    SObject oldS = trigger.oldMap.get(s.id);
    //do stuff

After getting the old object, you can get the Contact that matches this object and set the field to that old value.

  • i have trigger on child object season address.. not contact. i hope trigger.old provides old version record which it belongs to..
    – user30563
    Apr 12, 2016 at 1:25
  • No, it doesn't. Trigger.old just contains the value before the change was made during the act of changing. The old value does not exist after the trigger action is complete, it's a temporary variable. Apr 12, 2016 at 5:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .