• mlmilner
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

1) I have a trigger that works in sb and does exactly what I want it to do:

Class I wrote will not get it above 55% (when it passed)

2) Made a small change and now it does not pass, but not seeing what is wrong.

I know - should have made a backup before changing!

 

Thanks.

Forgot to post the code - one of those Mondays, and, the test was based on a post I saw; looks like it overdoes it, but I am new at this.

 

Trigger:

Trigger Pharmacy_Demo_Completed on Task (before insert){
   for (Task T : trigger.new){
      string TaskProfile = 'Implementation Director';
      string TaskSubject = t.subject;
      string TaskType = 'Send Contracts';
      if (TaskSubject == 'Pharmacy Demo Completed'){
          List <User> usr = [select Id from User where Profile.Name =:TaskProfile limit 1];
 //         system.debug (Usr.size());

//          If (Usr.size() < 1){
//            system.debug ('No entries found for ');}
                                       
//          if (usr.size() > 0)
                {User u = [select Id ,name from User where Profile.Name =:TaskProfile limit 1];
                t.ownerid = u.id;
                t.type = TaskType;}

Class:

@isTest
public class Taskusertest2 {
    List<Task> insertedTasks = new List<Task>{};
    static testMethod void myUnitTest() {
    for(Integer i = 0; i < 100; i++)    
        {Task t = new Task();
            t.IsRecurrence = FALSE;
            t.sma__CreatedLocationVerified__c = FALSE;
            t.IsReminderSet = FALSE;
            t.MA_Clean_State__c = 'tx';
            t.Subject = 'Testing';
            t.Type = 'Research';
            t.Priority = 'Normal';
            t.Description = 'Task Class Test';
            t.Status = 'Completed';
        insert t;}
        
         List<Task> insertedTasks = [SELECT Description
                                                FROM Task
                                                WHERE Status = 'Completed'];
         {for(Task t : insertedTasks)
          System.assertEquals(
          'This Task is probably left over from testing. It should probably be deleted.',
          t.Description);}
        
//        System.assertNotEquals(t.id, null);
    }}

I have a simple trigger that works in the sandbox, does exactly what I want it to do. Cannot get code coverage above 40%.

I also do not know how to see what code is not covered. The test class below was pieced together from samples I found.

Any help would be appreciated!

 

Trigger:

 

trigger Pharmacy_Demo_Completed on Task (before insert){
   for (Task T : trigger.new){
      string TaskProfile = 'Implementation Director';
      string TaskSubject = t.subject;
      string TaskType = 'Send Contracts';
      if (TaskSubject == 'Pharmacy Demo Completed'){
          List <User> usr = [select Id from User where Profile.Name =:TaskProfile limit 1];
          system.debug (Usr.size());

          If (Usr.size() < 1){
             system.debug ('No entries found for ');}
                                       
          if (usr.size() > 0){
                User u = [select Id ,name from User where Profile.Name =:TaskProfile limit 1];
                t.ownerid = u.id;
                t.type = TaskType;}
      
}
}
}
Test Class: (Saves without error)

 

@isTest
public class Taskusertest2 {
    List<Task> insertedTasks = new List<Task>{};
    static testMethod void myUnitTest() {
    for(Integer i = 0; i < 100; i++)    
        {Task t = new Task();
            t.IsRecurrence = FALSE;
            t.sma__CreatedLocationVerified__c = FALSE;
            t.IsReminderSet = FALSE;
            t.MA_Clean_State__c = 'tx';
            t.Subject = 'Testing';
            t.Type = 'Research';
            t.Priority = 'Normal';
            t.Description = 'Task Class Test';
            t.Status__c = 'Demo Scheduled';
            t.Status = 'Completed';
        insert t;}
        
         List<Task> insertedTasks = [SELECT Description
                                                FROM Task
                                                WHERE Status = 'Demo Scheduled'];
         {for(Task t : insertedTasks)
          System.assertEquals(
          'This Task is probably left over from testing. It should probably be deleted.',
          t.Description);}
        
    }}

 

1) I have a trigger that works in sb and does exactly what I want it to do:

Class I wrote will not get it above 55% (when it passed)

2) Made a small change and now it does not pass, but not seeing what is wrong.

I know - should have made a backup before changing!

 

Thanks.

Forgot to post the code - one of those Mondays, and, the test was based on a post I saw; looks like it overdoes it, but I am new at this.

 

Trigger:

Trigger Pharmacy_Demo_Completed on Task (before insert){
   for (Task T : trigger.new){
      string TaskProfile = 'Implementation Director';
      string TaskSubject = t.subject;
      string TaskType = 'Send Contracts';
      if (TaskSubject == 'Pharmacy Demo Completed'){
          List <User> usr = [select Id from User where Profile.Name =:TaskProfile limit 1];
 //         system.debug (Usr.size());

//          If (Usr.size() < 1){
//            system.debug ('No entries found for ');}
                                       
//          if (usr.size() > 0)
                {User u = [select Id ,name from User where Profile.Name =:TaskProfile limit 1];
                t.ownerid = u.id;
                t.type = TaskType;}

Class:

@isTest
public class Taskusertest2 {
    List<Task> insertedTasks = new List<Task>{};
    static testMethod void myUnitTest() {
    for(Integer i = 0; i < 100; i++)    
        {Task t = new Task();
            t.IsRecurrence = FALSE;
            t.sma__CreatedLocationVerified__c = FALSE;
            t.IsReminderSet = FALSE;
            t.MA_Clean_State__c = 'tx';
            t.Subject = 'Testing';
            t.Type = 'Research';
            t.Priority = 'Normal';
            t.Description = 'Task Class Test';
            t.Status = 'Completed';
        insert t;}
        
         List<Task> insertedTasks = [SELECT Description
                                                FROM Task
                                                WHERE Status = 'Completed'];
         {for(Task t : insertedTasks)
          System.assertEquals(
          'This Task is probably left over from testing. It should probably be deleted.',
          t.Description);}
        
//        System.assertNotEquals(t.id, null);
    }}

I have a simple trigger that works in the sandbox, does exactly what I want it to do. Cannot get code coverage above 40%.

I also do not know how to see what code is not covered. The test class below was pieced together from samples I found.

Any help would be appreciated!

 

Trigger:

 

trigger Pharmacy_Demo_Completed on Task (before insert){
   for (Task T : trigger.new){
      string TaskProfile = 'Implementation Director';
      string TaskSubject = t.subject;
      string TaskType = 'Send Contracts';
      if (TaskSubject == 'Pharmacy Demo Completed'){
          List <User> usr = [select Id from User where Profile.Name =:TaskProfile limit 1];
          system.debug (Usr.size());

          If (Usr.size() < 1){
             system.debug ('No entries found for ');}
                                       
          if (usr.size() > 0){
                User u = [select Id ,name from User where Profile.Name =:TaskProfile limit 1];
                t.ownerid = u.id;
                t.type = TaskType;}
      
}
}
}
Test Class: (Saves without error)

 

@isTest
public class Taskusertest2 {
    List<Task> insertedTasks = new List<Task>{};
    static testMethod void myUnitTest() {
    for(Integer i = 0; i < 100; i++)    
        {Task t = new Task();
            t.IsRecurrence = FALSE;
            t.sma__CreatedLocationVerified__c = FALSE;
            t.IsReminderSet = FALSE;
            t.MA_Clean_State__c = 'tx';
            t.Subject = 'Testing';
            t.Type = 'Research';
            t.Priority = 'Normal';
            t.Description = 'Task Class Test';
            t.Status__c = 'Demo Scheduled';
            t.Status = 'Completed';
        insert t;}
        
         List<Task> insertedTasks = [SELECT Description
                                                FROM Task
                                                WHERE Status = 'Demo Scheduled'];
         {for(Task t : insertedTasks)
          System.assertEquals(
          'This Task is probably left over from testing. It should probably be deleted.',
          t.Description);}
        
    }}