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
cbrocbro 

Test Class help (36% coverage) - Need to deactivate trigger

I need to deploy to production some code, and cannot because only 36% (9/25) of this trigger is covered.

 

I also need to remove this trigger (it's old and is no longer valid for the business - and was written by someone else).

 

Can someone help me with this test class for the following trigger?  Everything in RED is not being tested.

 

I am new to writing triggers and test classes - so any help is greatly appreciated for this newbie....

 

Thanks, 
Chris

 

Here is the Trigger:

 

	  trigger Lead_UpdateAccountsOwner on Lead (after update) {
 2	  
 3	  System.debug('DEBUG::DEBUG-->Lead_UpdateAccountOwner - Converted Account ID : '  + trigger.new[0].convertedAccountId );
 4	      
 5	      List<String> lstOfProfiles=new List<String>();
 6	      lstOfProfiles.add('Product Specialist Standard User');
 7	      lstOfProfiles.add('Product Specialist System Admin User');
 8	      
 9	      List<String> roleNames= new List<String>();
 10	      roleNames.add('PM SuperUser');
 11	      //calling function from validating class
 12	       Boolean resultp=ProfileValidator.validateLoginUserProfile(lstOfProfiles);
 13	       Boolean result = false;
 14	       result=  ProfileValidator.CheckLoginUserRole(UserInfo.getUSerId());
 15	       
 16	    if(result == true)
 17	    {
 18	   

//get converted account ids in set

 19	      set<id> accountIds = new Set<Id>();
 20	      set<id> contactIds = new Set<Id>();
 21	      
 22	      for(Lead ld: trigger.new)
 23	      {
 24	          accountIds.add(ld.convertedAccountId);
 

25

	          contactIds.add(ld.convertedContactId);
 26	      }
 27	      
 28	      //query all converted accounts with owenr id
 29	      Map<id,Account> map_AssociatedAccounts = new Map<id,Account> ([SELECT id, OwnerId from Account WHERE id in: accountIds and Type = 'Prospect']);
 30	      Map<id,Contact> map_AssociatedContacts = new Map<id,Contact> ([SELECT id, OwnerId from Contact WHERE id in: contactIds]);
 31	      
 32	      //change owner of associated accounts
 33	      for(Lead ld: trigger.new)
 34	        {
 35	           Account act = map_AssociatedAccounts.get(ld.convertedAccountId);
 36	           if(act!=null)
 37	            {
 38	               act.OwnerId = ld.OwnerId;
 39	            }
 40	           
 41	           Contact con = map_AssociatedContacts.get(ld.convertedContactId);
 42	           if(con!=null)
 43	            {
 44	               con.OwnerId = ld.OwnerId;
 45	            }
 46	        }
 47	      
 48	      //update accounts
 49	      update map_AssociatedAccounts.values();
 50	      update map_AssociatedContacts.values();
 51	  
 52	  
 53	    }
 54	   
 55	  
 56	  }

 

See associated Test Classes below (60% 9/15):

 

global class LeadOwnerChange implements Database.Batchable<sObject>
{
List<Group> que;
public  LeadOwnerChange ()
 {
   que = new List<Group>(); 
   que = [Select Id ,Type,Name From Group where Name = 'Product Specialist Marketing Group' and type='queue' limit 1];
 }
public String Query{get;set;}
 
 
global Database.QueryLocator start(Database.BatchableContext BC)
   {
     return Database.getQueryLocator(Query);
   }

 global void execute(Database.BatchableContext BC,List<Lead> batch)
   { 
   if(que.size()>0)
   {
     for (Lead led :batch)
      {
      System.Debug('BBBBBBBBBBB'+que);
         System.Debug('AAAAAAAAAA'+led);
        led.OwnerId= que[0].id;
      }
   update batch;
    
   }
   }
  global void finish(Database.BatchableContext BC) 
  {
    
  }
}

 

Here is a second Test Class that is trying to do something...  (25% 1/4)

 

global with sharing class ScheduleLeadOwnerChange implements Schedulable 
{   
    global void execute(SchedulableContext SC)
     {
 
         LeadOwnerChange leadUpdate = new LeadOwnerChange();
         leadUpdate.Query = 'Select l.Id From Lead l  where l.IsConverted = false and l.CreatedDate   < LAST_90_DAYS';
         
         
         Database.ExecuteBatch(leadUpdate ,200);
         
         
         }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
Starz26Starz26

Neither of those appear to be test classes. They are batch classes.

 

If you want to simply delete the trigger:

 

1. Open up eclipse and connect to your prod org

2. Include the trigger in the selected items

3. Open the trigger xml file

4. change "Active" to "Deleted"

5. save

All Answers

Starz26Starz26

Neither of those appear to be test classes. They are batch classes.

 

If you want to simply delete the trigger:

 

1. Open up eclipse and connect to your prod org

2. Include the trigger in the selected items

3. Open the trigger xml file

4. change "Active" to "Deleted"

5. save

This was selected as the best answer
cbrocbro

Hmmm.  I didn't think I could delete a trigger from production if it only has 36% test coverage.

 

However, it did work.  

 

Good times.  Thanks!

 

Chris