• CRMsantabarbara
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 8
    Replies

Hi,  my trigger only fires for the first record in the batch when performing a dataloader insert.  Any ideas on how to get it to fire for all the records in each batch?  Dataloader is set to batchs of 200.  I don't want to reduce the batch to a count of 1, I need it to do bulk.  The trigger is designed to perform a vlookup (using the zip code on the lead as a reference) on a custom object (Postal Code Test)  and populate a custom field on the Lead object.  Each record on the Postal Code Test object contains a zip code and a corresponding internal territory.

 

here's the trigger:

 

trigger UpdateLeadAreaAssign on Lead (before Insert, before Update) {

    try {

        for(Lead x : Trigger.New) {

            //set to no area until it finds a territory matching the zip

            x.Lead_Territory_Trigger__c = 'NOAREA';

           

            //fetch territory from custom object using postal code from lead

            List<Postal_Code_Test__c> triggerLeadArea =

                [SELECT p.Lead_Territory__c

                FROM Postal_Code_Test__c p

                WHERE Zip_Code__c =: x.PostalCode

                LIMIT 1];

           

            //update lead territory field on lead

            x.Lead_Territory_Trigger__c = triggerLeadArea[0].Lead_Territory__c;       

        }

    } 

    catch (Exception e) {      

        System.Debug('ERROR: ' + e);

    }

}

Hi,  my trigger only fires for the first record in the batch when performing a dataloader insert.  Any ideas on how to get it to fire for all the records in each batch?  Dataloader is set to batchs of 200.  I don't want to reduce the batch to a count of 1, I need it to do bulk.  The trigger is designed to perform a vlookup (using the zip code on the lead as a reference) on a custom object (Postal Code Test)  and populate a custom field on the Lead object.  Each record on the Postal Code Test object contains a zip code and a corresponding internal territory.

 

here's the trigger:

 

trigger UpdateLeadAreaAssign on Lead (before Insert, before Update) {

    try {

        for(Lead x : Trigger.New) {

            //set to no area until it finds a territory matching the zip

            x.Lead_Territory_Trigger__c = 'NOAREA';

           

            //fetch territory from custom object using postal code from lead

            List<Postal_Code_Test__c> triggerLeadArea =

                [SELECT p.Lead_Territory__c

                FROM Postal_Code_Test__c p

                WHERE Zip_Code__c =: x.PostalCode

                LIMIT 1];

           

            //update lead territory field on lead

            x.Lead_Territory_Trigger__c = triggerLeadArea[0].Lead_Territory__c;       

        }

    } 

    catch (Exception e) {      

        System.Debug('ERROR: ' + e);

    }

}