• Sean Grove
  • NEWBIE
  • 10 Points
  • Member since 2020

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

Ive created an apex class that pulls in certain leads and then feeds all the IDs into a round robin assigner apex class. Im not a developer but Ive been able to hack together enough to get this running as intended, my only problem now is the text class I have doesnt have enough code coverage to get into production. I assume part of this problem is the List that is created does not have its own method and therefore is hard to create a test for? But agian Im not a developer, Ive included both the class as well as the test code. If someone could point me in the right direction that would be greatly appreciated!

CODE:

public with sharing class RRAOnline {

    list<roundRobinAssigner.RoundRobinAssignment> rras = new list<roundRobinAssigner.RoundRobinAssignment>();

    List<User> users = [SELECT Id FROM User WHERE Lead_Reassignment__c = true AND IsActive = true AND ProfileId = '00e4P000000KDMk'];
 
    List<Lead> leads = [SELECT Id 
                        FROM Lead
                        WHERE OwnerID IN : users
                        AND Next_Business_Date__c <= TODAY 
                        AND (
                        Program_of_Interest__c = 'Animation' OR
                        Program_of_Interest__c = 'Fashion Design' OR
                        Program_of_Interest__c = 'Fine Arts' OR
                        Program_of_Interest__c = 'Game Art' OR
                        Program_of_Interest__c = 'Graphic Design' OR
                        Program_of_Interest__c = 'Illustration' OR
                        Program_of_Interest__c = 'Illustrative Design' OR
                        Program_of_Interest__c = 'Interior Design' OR
                        Program_of_Interest__c = 'Non-Degree Seeking' OR
                        Program_of_Interest__c = 'Photography' OR
                        Program_of_Interest__c = 'Summer Camp' OR
                        Program_of_Interest__c = 'Undeclared' OR
                        Program_of_Interest__c = 'Certificate Program - Graduate'
                        )
                        AND (
                        Status__c = 'New' OR 
                        Status__c = 'Attempting Contact 1' OR
                        Status__c = 'Attempting Contact 2' OR
                        Status__c = 'Attempting Contact 3' OR
                        Status__c = 'Attempting Contact 4' OR
                        Status__c = 'Attempting Contact 5')
                        LIMIT 50
                        ];
                  
     public void createrrassigns(){
        for (lead a:leads){
            roundRobinAssigner.RoundRobinAssignment rra = new roundRobinAssigner.RoundRobinAssignment();
            rra.groupName = 'Online Round Robin';
            rra.recordId = a.id;
            rra.fieldName = 'OwnerId';
            rras.add(rra);
            }
        if (rras.size() > 0){
            roundRobinAssigner.assign(rras);
            } 
         else {
            system.debug('list is empty');
            }
      }


}



TEST CODE:


@isTest
private class RRAOnline_Test{
  @testSetup
  static void setupTestData(){
    test.startTest();
    
    // Setup 4 Test Leads
    List<Lead> leads = new List<Lead>();

    while (leads.size() < 5) {
      Blob b = Crypto.GenerateAESKey(128);
      String h = EncodingUtil.ConvertTohex(b);
      String uid = h.SubString(0,8);
      Lead l = new Lead(FirstName = 'FirstName'+ uid, LastName = 'LastName'+ uid, Status = 'New Inquiry', Status__c = 'New', Program_of_Interest__c = 'Graphic Design', 
            Next_Business_Date__c = System.today());      
      leads.add(l);
    }
    insert(leads);
    
    
     
    // Setup 4 Test Users
    Profile p = [SELECT Id FROM Profile WHERE Name='Admissions User']; 
    List<User> user_Obj = new List<User>();

    while (user_Obj.size() < 5) {
      Blob b = Crypto.GenerateAESKey(128);
      String h = EncodingUtil.ConvertTohex(b);
      String uid = h.SubString(0,8);
      User u = new User(Alias = uid, Email= uid + '@myorg.com', 
          EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', ProfileId = p.Id, 
          TimeZoneSidKey='America/New_York', UserName= uid + '@myorg.com', Lead_Reassignment__c = true, IsActive = true);      
      user_Obj.add(u);
    }
    insert(user_Obj);

    test.stopTest();
  }
  
    static testMethod void test_createrrassigns_UseCase1(){
    RRAOnline obj01 = new RRAOnline();
    obj01.createrrassigns();
  }
  
//    static testMethod void test_createrrassigns_UseCase2(){
//    RRAOnline users = new RRAOnline();
//    users.getUsers();
//  }
  

}

Ive created an apex class that pulls in certain leads and then feeds all the IDs into a round robin assigner apex class. Im not a developer but Ive been able to hack together enough to get this running as intended, my only problem now is the text class I have doesnt have enough code coverage to get into production. I assume part of this problem is the List that is created does not have its own method and therefore is hard to create a test for? But agian Im not a developer, Ive included both the class as well as the test code. If someone could point me in the right direction that would be greatly appreciated!

CODE:

public with sharing class RRAOnline {

    list<roundRobinAssigner.RoundRobinAssignment> rras = new list<roundRobinAssigner.RoundRobinAssignment>();

    List<User> users = [SELECT Id FROM User WHERE Lead_Reassignment__c = true AND IsActive = true AND ProfileId = '00e4P000000KDMk'];
 
    List<Lead> leads = [SELECT Id 
                        FROM Lead
                        WHERE OwnerID IN : users
                        AND Next_Business_Date__c <= TODAY 
                        AND (
                        Program_of_Interest__c = 'Animation' OR
                        Program_of_Interest__c = 'Fashion Design' OR
                        Program_of_Interest__c = 'Fine Arts' OR
                        Program_of_Interest__c = 'Game Art' OR
                        Program_of_Interest__c = 'Graphic Design' OR
                        Program_of_Interest__c = 'Illustration' OR
                        Program_of_Interest__c = 'Illustrative Design' OR
                        Program_of_Interest__c = 'Interior Design' OR
                        Program_of_Interest__c = 'Non-Degree Seeking' OR
                        Program_of_Interest__c = 'Photography' OR
                        Program_of_Interest__c = 'Summer Camp' OR
                        Program_of_Interest__c = 'Undeclared' OR
                        Program_of_Interest__c = 'Certificate Program - Graduate'
                        )
                        AND (
                        Status__c = 'New' OR 
                        Status__c = 'Attempting Contact 1' OR
                        Status__c = 'Attempting Contact 2' OR
                        Status__c = 'Attempting Contact 3' OR
                        Status__c = 'Attempting Contact 4' OR
                        Status__c = 'Attempting Contact 5')
                        LIMIT 50
                        ];
                  
     public void createrrassigns(){
        for (lead a:leads){
            roundRobinAssigner.RoundRobinAssignment rra = new roundRobinAssigner.RoundRobinAssignment();
            rra.groupName = 'Online Round Robin';
            rra.recordId = a.id;
            rra.fieldName = 'OwnerId';
            rras.add(rra);
            }
        if (rras.size() > 0){
            roundRobinAssigner.assign(rras);
            } 
         else {
            system.debug('list is empty');
            }
      }


}



TEST CODE:


@isTest
private class RRAOnline_Test{
  @testSetup
  static void setupTestData(){
    test.startTest();
    
    // Setup 4 Test Leads
    List<Lead> leads = new List<Lead>();

    while (leads.size() < 5) {
      Blob b = Crypto.GenerateAESKey(128);
      String h = EncodingUtil.ConvertTohex(b);
      String uid = h.SubString(0,8);
      Lead l = new Lead(FirstName = 'FirstName'+ uid, LastName = 'LastName'+ uid, Status = 'New Inquiry', Status__c = 'New', Program_of_Interest__c = 'Graphic Design', 
            Next_Business_Date__c = System.today());      
      leads.add(l);
    }
    insert(leads);
    
    
     
    // Setup 4 Test Users
    Profile p = [SELECT Id FROM Profile WHERE Name='Admissions User']; 
    List<User> user_Obj = new List<User>();

    while (user_Obj.size() < 5) {
      Blob b = Crypto.GenerateAESKey(128);
      String h = EncodingUtil.ConvertTohex(b);
      String uid = h.SubString(0,8);
      User u = new User(Alias = uid, Email= uid + '@myorg.com', 
          EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
          LocaleSidKey='en_US', ProfileId = p.Id, 
          TimeZoneSidKey='America/New_York', UserName= uid + '@myorg.com', Lead_Reassignment__c = true, IsActive = true);      
      user_Obj.add(u);
    }
    insert(user_Obj);

    test.stopTest();
  }
  
    static testMethod void test_createrrassigns_UseCase1(){
    RRAOnline obj01 = new RRAOnline();
    obj01.createrrassigns();
  }
  
//    static testMethod void test_createrrassigns_UseCase2(){
//    RRAOnline users = new RRAOnline();
//    users.getUsers();
//  }
  

}