3

I have code called from the before update/before insert triggers that looks at the Country value, and if found or is changed, we call some custom code to find a matching record in a custom Territory object. I'm having an issue with the country and state picklist where the actual Country field is null before insert but the CountryCode is filled in. Then if we have workflow force an immediate update, we hit the update trigger but now if we compare old and new Country they are both set to the same value. It seems like the Country value gets populated by SF sometime after the triggers are run but doesn't fire a trigger itself. As such, I can't seem to run my logic when the Country is populated on insert. Anyone else come across this?

    public static void testAssignmentCountry( Map<Id, Lead> oldMap, List<Lead> newList) {

    for (Lead l : newList) {
            system.debug('lead new country: '+l.country);
            system.debug('lead new country code: '+l.CountryCode);
            if (l.country != null && (oldMap == null || oldMap.get(l.id).country != l.country))
                system.debug('run territory lookup for country: '+l.country);
    }

}

When I run this for a new lead with workflow that causes an update, I get the debug of:

lead new country: null
lead new country code: CA
lead new country: Canada
lead new country code: CA
  • Any updates on above issue ? I'm facing same Issue. – user28635 Feb 9 '16 at 20:42
  • can you use an after insert/update trigger instead? – cropredy Feb 10 '16 at 0:01
  • i believe after insert/update would work but in my scenario I needed to also edit the same lead after inspecting the country value. To solve this I ended up calling a future method in the after trigger to then do something and make further edits. Too bad as it creates extra processing but I couldn't find another solution. – nikiV Feb 10 '16 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.