We have many workflow rules on the account Object, one of it is it prevents the users from entering wrong data in to Location__c
.I recently created a Trigger on the Account Object which looks for a field Location__c
if it is changed I need the Trigger to be fired which makes a callout to POST this change to external system.
trigger updateLoccation Account (after update) {
if(trigger.isupdate)
{
set<Id> AccountIds = new Set<Id>();
for( Id accountId : Trigger.newMap.keySet() ){
System.debug('## Old Value of Location' +Trigger.oldMap.get(accountId).Location__c);
System.debug('## New Value of Location' + Trigger.newMap.get(accountId).Location__c);
if( (Trigger.oldMap.get(accountId).Location__c != Trigger.newMap.get(accountId).Location__c))
{
AccountIds.add(accountId);
}
}
If in the UI I make the change to Location__c
on the Account Record say NY to TN
, the trigger is fired and the callout is made to external system. Then the Workflow rules on the Account record is executed which basically checks if the Location assigned is right and set it back to NY
.Then again the trigger is fired but the old and new value of the field is NY
so nothing happens. So the issue is two systems are out of sync, SF has 'NY' and External system has 'TN'. I need the external system know only when the changes happen on the field. Can anyone say why after the workflow field update I see the old and new value on the trigger same. How can I handle is this scenario any help is greatly appreciated