• Will Bauzon
  • NEWBIE
  • 20 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
Hello there,

I'm still pretty new to code development and I am using the following trigger and class.

Trigger:
trigger AccountTerritoryTag on Account (before insert, before update)
{
    Set<String> setName =  new Set<String>();
    for (Account account : Trigger.new)
    {       
        if (account.RunAssignment__c == TRUE)
        {
            setName.add(account.RoutingKey__c);
        }   
    }   
    
    if(setName.size() > 0 )
    {
        List<RoutingKey__c> routingkey = [select Name,Territory__c from RoutingKey__c  where Name in :setName ];
        Map<String, RoutingKey__c> mapNameWiseR = new  Map<String, RoutingKey__c> ();
        for(RoutingKey__c  RK : routingkey )
        {
            mapNameWiseR.put(RK.Name , RK);
        }

        for (Account account : Trigger.new)
        {    
          if (account.RunAssignment__c == TRUE)
          {
              if (mapNameWiseR.containsKey(account.RoutingKey__c) )
              {   
                    RoutingKey__c rk = mapNameWiseR.get(account.RoutingKey__c);
                  //assign the territory 
                    account.Territory__c = rk.Territory__c;
                    account.RunAssignment__c = FALSE;
             
              }
           }
        }
        
    }
        
}


Test Class:
@isTest

private class AccountTerritoryTest
{
    static testMethod void AccountTerritoryTest()
    { 
       Territory__c t = new Territory__c();
       t.Name = 'TerritoryTest';
       insert t;
       
       RoutingKey__c k = new RoutingKey__c();
       k.Name = 'NAM|SMB|FL';
       k.Territory__c = t.id;
       insert k;
       
       Account a = new Account();
       a.Name  = 'Test';
       a.OverrideCountry__c = 'US';
       a.OverrideEmployees__c = 'A) 1-100';
       a.OverrideState__c = 'FL';
       a.RunAssignment__c = TRUE;
       insert a;
       
       a.RunAssignment__c  =  FALSE;
       a.Territory__c = t.id;
       update a;
       
    }
    
}

I'm stuck at 72% coverage and would like to increase as much as possible. I looked at my dev console and lines 17, 18, and 27-30 are uncovered by my class. I'm not certain how to write the class to cover these lines and the account update doesn't cover it. Can someone help/explain what I can do to fix this? Thank you in advance for the help!
 
Hi there,

I'm using the following code to trigger a lookup to a custom object on the account. I'm currently hitting SOQL limits on this and I think its because I have a DML statement inside the loop.
 
trigger AccountTerritoryTag on Account (before insert, before update)
{
    List<Account> accountsToUpdate = new List<Account>();

    for (Account account : Trigger.new)
    {    
      if (account.RunAssignment__c == TRUE)
      {
          // Find the territory using routing kew
          List<RoutingKey__c> routingkey = [select Name,Territory__c from RoutingKey__c
                             where Name = :account.RoutingKey__c limit 1];     
               
          // if you found one
          if (routingkey.size() > 0)
          {   
              //assign the territory 
              account.Territory__c = routingkey[0].Territory__c;
              account.RunAssignment__c = FALSE;
         
              accountsToUpdate.add(account);
         
          }
       }
    }
}

Also, when I try to deploy this trigger into prod using this class, I get a coverage error saying that there is no coverage at all even though I have 100% coverage in sandox.
 
@isTest

private class AccountTerritoryTest
{
    static testMethod void AccountTerritoryTest()
    { 
       RoutingKey__c k = new RoutingKey__c();
       k.Name = 'FL';
       insert k;
       
       Account a = new Account();
       a.Name  = 'Test';
       a.RoutingKey__c =  'FL';
       a.RunAssignment__c = TRUE;
       insert a;
       
       a.RunAssignment__c  =  FALSE;
       update a;
       
    }
    
}

I'm fairly new to coding and would greatly appreicate any help you could provide!
Is there a way to set up either a week dump or email notification of when an administrator creates a custom field in SFDC? This is critical for my ETL guys to know so that they can add the fields to their scripts.
Hello there,

I'm still pretty new to code development and I am using the following trigger and class.

Trigger:
trigger AccountTerritoryTag on Account (before insert, before update)
{
    Set<String> setName =  new Set<String>();
    for (Account account : Trigger.new)
    {       
        if (account.RunAssignment__c == TRUE)
        {
            setName.add(account.RoutingKey__c);
        }   
    }   
    
    if(setName.size() > 0 )
    {
        List<RoutingKey__c> routingkey = [select Name,Territory__c from RoutingKey__c  where Name in :setName ];
        Map<String, RoutingKey__c> mapNameWiseR = new  Map<String, RoutingKey__c> ();
        for(RoutingKey__c  RK : routingkey )
        {
            mapNameWiseR.put(RK.Name , RK);
        }

        for (Account account : Trigger.new)
        {    
          if (account.RunAssignment__c == TRUE)
          {
              if (mapNameWiseR.containsKey(account.RoutingKey__c) )
              {   
                    RoutingKey__c rk = mapNameWiseR.get(account.RoutingKey__c);
                  //assign the territory 
                    account.Territory__c = rk.Territory__c;
                    account.RunAssignment__c = FALSE;
             
              }
           }
        }
        
    }
        
}


Test Class:
@isTest

private class AccountTerritoryTest
{
    static testMethod void AccountTerritoryTest()
    { 
       Territory__c t = new Territory__c();
       t.Name = 'TerritoryTest';
       insert t;
       
       RoutingKey__c k = new RoutingKey__c();
       k.Name = 'NAM|SMB|FL';
       k.Territory__c = t.id;
       insert k;
       
       Account a = new Account();
       a.Name  = 'Test';
       a.OverrideCountry__c = 'US';
       a.OverrideEmployees__c = 'A) 1-100';
       a.OverrideState__c = 'FL';
       a.RunAssignment__c = TRUE;
       insert a;
       
       a.RunAssignment__c  =  FALSE;
       a.Territory__c = t.id;
       update a;
       
    }
    
}

I'm stuck at 72% coverage and would like to increase as much as possible. I looked at my dev console and lines 17, 18, and 27-30 are uncovered by my class. I'm not certain how to write the class to cover these lines and the account update doesn't cover it. Can someone help/explain what I can do to fix this? Thank you in advance for the help!
 
Hi there,

I'm using the following code to trigger a lookup to a custom object on the account. I'm currently hitting SOQL limits on this and I think its because I have a DML statement inside the loop.
 
trigger AccountTerritoryTag on Account (before insert, before update)
{
    List<Account> accountsToUpdate = new List<Account>();

    for (Account account : Trigger.new)
    {    
      if (account.RunAssignment__c == TRUE)
      {
          // Find the territory using routing kew
          List<RoutingKey__c> routingkey = [select Name,Territory__c from RoutingKey__c
                             where Name = :account.RoutingKey__c limit 1];     
               
          // if you found one
          if (routingkey.size() > 0)
          {   
              //assign the territory 
              account.Territory__c = routingkey[0].Territory__c;
              account.RunAssignment__c = FALSE;
         
              accountsToUpdate.add(account);
         
          }
       }
    }
}

Also, when I try to deploy this trigger into prod using this class, I get a coverage error saying that there is no coverage at all even though I have 100% coverage in sandox.
 
@isTest

private class AccountTerritoryTest
{
    static testMethod void AccountTerritoryTest()
    { 
       RoutingKey__c k = new RoutingKey__c();
       k.Name = 'FL';
       insert k;
       
       Account a = new Account();
       a.Name  = 'Test';
       a.RoutingKey__c =  'FL';
       a.RunAssignment__c = TRUE;
       insert a;
       
       a.RunAssignment__c  =  FALSE;
       update a;
       
    }
    
}

I'm fairly new to coding and would greatly appreicate any help you could provide!