Skip to main content
Tweeted twitter.com/#!/StackSalesforce/status/274871787580452864
added 2 characters in body
Source Link
Peter Knolle
  • 29.2k
  • 12
  • 104
  • 164

Well today while working with triggers I observed a weird issue. In my org I have a object called Demo__cDemo__c and which has a standard "Name" field and another field called "TimeStamp__c". I have a following trigger on this object .

    trigger DemoTrigger on Demo__c (before update,after update) {
    for(Demo__c demo : trigger.new){
        if(demo.name!=trigger.oldMap.get(demo.Id).name){
            System.debug('New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name);
        }
        else{
            System.debug('#######SAME##############');
        }
    }
}

And a worflow that updates the "TimeStamp__c" field everytime the record is updated. So when am updating the "Name" field what I was expecting is to see this line "New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name" in the debug and when the workflow is firing I was expecting #######SAME############## since this will invoke the trigger again but somehow things are adding up after field am seeing "New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name" again in the debug. Am really confused just wanted to know if it is the expected behaviour?

Well today while working with triggers I observed a weird issue. In my org I have a object called Demo__c and which has a standard "Name" field and another field called "TimeStamp__c". I have a following trigger on this object .

    trigger DemoTrigger on Demo__c (before update,after update) {
    for(Demo__c demo : trigger.new){
        if(demo.name!=trigger.oldMap.get(demo.Id).name){
            System.debug('New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name);
        }
        else{
            System.debug('#######SAME##############');
        }
    }
}

And a worflow that updates the "TimeStamp__c" field everytime the record is updated. So when am updating the "Name" field what I was expecting is to see this line "New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name" in the debug and when the workflow is firing I was expecting #######SAME############## since this will invoke the trigger again but somehow things are adding up after field am seeing "New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name" again in the debug. Am really confused just wanted to know if it is the expected behaviour?

Well today while working with triggers I observed a weird issue. In my org I have a object called Demo__c and which has a standard "Name" field and another field called "TimeStamp__c". I have a following trigger on this object .

    trigger DemoTrigger on Demo__c (before update,after update) {
    for(Demo__c demo : trigger.new){
        if(demo.name!=trigger.oldMap.get(demo.Id).name){
            System.debug('New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name);
        }
        else{
            System.debug('#######SAME##############');
        }
    }
}

And a worflow that updates the "TimeStamp__c" field everytime the record is updated. So when am updating the "Name" field what I was expecting is to see this line "New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name" in the debug and when the workflow is firing I was expecting #######SAME############## since this will invoke the trigger again but somehow things are adding up after field am seeing "New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name" again in the debug. Am really confused just wanted to know if it is the expected behaviour?

Source Link
Avidev9
  • 5.7k
  • 4
  • 38
  • 50

Trigger behavior with Field Update

Well today while working with triggers I observed a weird issue. In my org I have a object called Demo__c and which has a standard "Name" field and another field called "TimeStamp__c". I have a following trigger on this object .

    trigger DemoTrigger on Demo__c (before update,after update) {
    for(Demo__c demo : trigger.new){
        if(demo.name!=trigger.oldMap.get(demo.Id).name){
            System.debug('New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name);
        }
        else{
            System.debug('#######SAME##############');
        }
    }
}

And a worflow that updates the "TimeStamp__c" field everytime the record is updated. So when am updating the "Name" field what I was expecting is to see this line "New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name" in the debug and when the workflow is firing I was expecting #######SAME############## since this will invoke the trigger again but somehow things are adding up after field am seeing "New-->'+demo.name+'<-------'+trigger.oldMap.get(demo.Id).name" again in the debug. Am really confused just wanted to know if it is the expected behaviour?