• Nland
  • NEWBIE
  • 25 Points
  • Member since 2010

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

I have been trying to write a test class for this trigger, but have been unsuccessful on getting the code coverage that I need to move it into production. 

 

trigger LeadAssignmentTrigger on Lead (before insert) 
{    
    List<String> zips = new List<String>();

    // Loop through Leads and create list of zip codes
    for (Lead lead : Trigger.new)
    {
        if (lead.PostalCode != NULL && lead.Assign_Using_Assignment_Rules__c == true)
        {
            zips.add(lead.PostalCode);    
        }
    }

    //query zip code table and link zips to Sales reps
    Map<String, Zip_Code__c> leadsToUpdate = new Map<String, Zip_Code__c>();

    for(Zip_Code__c zip_code:[select Name, Owner.Id from Zip_Code__c where Name in :zips]) 
    { 
       if(zip_code.Name != null) leadsToUpdate.put(zip_code.Name, zip_code);
    } 


    // If there is at least one match, bulk update
    if (leadsToUpdate.size() > 0)
    {
        
        for (Lead lead : Trigger.new)
        {
            // only update if the lead zip code exists in the Map
            if (leadsToUpdate.containsKey(lead.PostalCode))
            {
              //assign the lead owner to the zip code owner
              lead.OwnerId = leadsToUpdate.get(lead.PostalCode).OwnerId;    
            }
        }
          
     }     
}

Any help would be very much appreciated....

Thanks

NL

  • September 30, 2010
  • Like
  • 0

I am working on the "Task" fields for  "Activities" and trying to create a validation rule based on two different picklist values.


The following is my formula, but I have no idea how to keep from getting errors........


AND(ISPICKVAL( Subject ,"AOP"),(ISPICKVAL( AOP_Task_Type__c ,"")))

Error: Incorrect parameter for function ISPICKVAL(). Expected Picklist, received Text

 

I have tried many different ways to get this to work with no success....

 

Scenario: If "AOP" is chosen as the subject, an AOP_Task_Type field is required. (Both fields are picklists)

 

Any help would be greatly appreciated....

 

Thanks

  • September 29, 2010
  • Like
  • 0

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 

  }

  • September 24, 2010
  • Like
  • 0

I am working on the "Task" fields for  "Activities" and trying to create a validation rule based on two different picklist values.


The following is my formula, but I have no idea how to keep from getting errors........


AND(ISPICKVAL( Subject ,"AOP"),(ISPICKVAL( AOP_Task_Type__c ,"")))

Error: Incorrect parameter for function ISPICKVAL(). Expected Picklist, received Text

 

I have tried many different ways to get this to work with no success....

 

Scenario: If "AOP" is chosen as the subject, an AOP_Task_Type field is required. (Both fields are picklists)

 

Any help would be greatly appreciated....

 

Thanks

  • September 29, 2010
  • Like
  • 0