2

I have an issue with an auto-response rule that isn't working in our live environment (but does work in our sandboxes). The lead auto-response rule doesn't fire even though the simple criteria is fulfilled (a hard-coded value on the web to lead form).

Upon disabling the following trigger, the auto-response rule works ok. When enabled, the trigger works as expected but the auto-response doesn't get sent. Can anyone see any issues with my trigger? Its purpose is to set the Sales region based on the specified country (from a drop down).

trigger Lead_UpdateSalesRegion on Lead (after insert, after update) {

    List<Lead> leadList = new List<Lead>();

    for (Lead ld : trigger.new) {

        // use the custom settings to find the region for the country entered.    
        If (ld.Country != null && CountryRegionList__c.getInstance(ld.Country) != null) {

            String oldCtry;

            if ( trigger.isUpdate )  {                
                Lead oldLd = trigger.oldMap.get(ld.id);            
                oldCtry = oldLd.Country;
                System.debug('Old Country: ' + oldCtry);
            }

            String salesRegion = CountryRegionList__c.getInstance(ld.Country).Region__c;
            if (salesRegion != null && ld.Country != oldCtry) {

                Lead newLead = new Lead(id = ld.id, Sales_Region__c = salesRegion);
                leadList.add(newLead);

            }

        }
    }

    if(leadList.size()>0) update leadList; 

}
2

Salesforce have advised "that when using triggers and auto-response rules it is always better to use this piece of code to trigger it manually."

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_database_dmloptions.htm

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.