You need to sign in to do that
Don't have an account?

Tricky Trigger Problem
I'm having issues with not getting this to fire all of the time:
trigger InsertACHupdateDate on Account (before update) { map<id,account> oldMap = new map<id,account>(); map<id,account> newMap = new map<id,account>(); for(Account acctOld : trigger.old) { oldMap.put(acctOld.id, acctOld); } for(account acctNew : trigger.new) { newMap.put(acctNew.id, acctNew); } for(account a :trigger.new) { boolean updateCheck = false; account oldA = oldMap.get(a.id); account newA = newMap.get(a.id); if(oldA.Routing_Number_enc__c != null && newA.Routing_Number_enc__c != null) if(oldA.Routing_Number_enc__c != newA.Routing_Number_enc__c) updateCheck = true; if(oldA.Account_Number__c != null && newA.Account_Number__c != null) if(oldA.Account_Number__c != newA.Account_Number__c) updateCheck = true; if(oldA.BillingStreet!=newA.BillingStreet) updateCheck = true; if(oldA.BillingCity!=newA.BillingCity) updateCheck = true; if(oldA.BillingState!=newA.BillingState) updateCheck = true; if(oldA.BillingPostalCode!=newA.BillingPostalCode) updateCheck = true; if(oldA.BillingCountry!=newA.BillingCountry) updateCheck = true; if(oldA.Payable_To__c!=newA.Payable_To__c) updateCheck = true; if(updateCheck) { a.Last_ACH_Update__c = System.Today(); } } }
It will fire if there is info in the field and it changes but not when it is first filled in for the Account# field and Routing field.
Thanks,
I think there should be OR conditions (instead of AND) for both Account Number and routing fields.
but now if the fields are blank the field gets populated even though nothing has changed.
Give it a try
That is how I originally wrote it yesterday before I moved to this version. When I debug the issue appears that if both fields are blank the newA.number returns nothing - not even a null but the oldA.number returns null if it is null so it reads as they are different and updates the field.
thanks!
With old and new i refer to field values.
Try this and Let me know if it does not work.
the only time it doesn't work is if both fields are blank.
I believe you used this condition.
If both the fields are blank means the field is not been updated, so the field must not be populated, Right?.
I think you dont need to use the first if conditions... these are allowing the trigger to proceed further only when the fields are not blank..if they are blank..nothing in your trigger gets executed..
you simply need to keep the inner if..remove the outer if statements..your trigger will work every time the record is updated..that is when thenew values and old values are different..
Instead of writing like this:
Write like this:
The issue is with the map the new value doesn't return anything if it's blank. Not even null. It's like the new value doesn't exist.
here's a shot of the debug log
This was ran when both fields were blank.
Whats datatype of Account Number and Routing?
encrypted text
Can you post the modified code where you had put debug.
Please post output of this:
Nothing showed?
Try this,