function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NlandNland 

Having a problem with my testing in order to move my trigger to production

I am lost here.  I have created the trigger in my sandbox and am trying to move it over to production.  The only problem I am having is in the testing.  I am hitting 58% and have no idea why.  The following is what I am getting. Any help would be very much appreciated.....(The only error message that I receive is that it failed)

 

LeadAssignmentTrigger (Code Covered: 58%)

 

 line  executions source
 1   trigger LeadAssignmentTrigger on Lead (before insert)
 2   {
 3 1   List<String> zips = new List<String>();

   
 5   
 6 1   for (Lead lead : Trigger.new)
 7    {
 8 6   if (lead.PostalCode != NULL && lead.Assign_Using_Assignment_Rules__c == true)
 9    {
 10 3   zips.add(lead.PostalCode);
 11    }
 12    }
 13   
 14   
 15 1   Map<String, Zip_Code__c> leadsToUpdate = new Map<String, Zip_Code__c>();
 16   
 17 1   for(Zip_Code__c zip_code:[select Name, Owner.Id from Zip_Code__c where Name in :zips])
 18    {
 19 0   if(zip_code.Name != null) leadsToUpdate.put(zip_code.Name, zip_code);
 20    }
 21   
 22   
 23   
 24 1   if (leadsToUpdate.size() > 0)
 25    {
 26   
 27 0   for (Lead lead : Trigger.new)
 28    {
 29   
 30 0   if (leadsToUpdate.containsKey(lead.PostalCode))
 31    {
 32   
 33 0   lead.OwnerId = leadsToUpdate.get(lead.PostalCode).OwnerId;
 34    }
 35    }
 36   
 37    }
 38 

  }

SargeSarge

Hi,

 

   I guess, the variable "zips" is not containing any values when you try running test class for this tigger.

 

I suggest you to put a debug after line 13 which will output the contents of variable "zips".

 

Due to empty list of strings, the query in SOQL for loop is empty and rest of the code possibly doesnt execute.

 

Make sure you are inserting lead records which will satisfy

lead.PostalCode != NULL && lead.Assign_Using_Assignment_Rules__c == true

 

i.e all records in lead insert should have PostalCode with some value and Assign_Using_Assignment_Rules as true.

So that the variable "zips" will have some items and SOQL for loop executes.

 

Hope this helps