System.QueryException: в списке нет строк для присвоения SObject Error в тестовом классе

Ниже приведен тестовый класс и связанный с ним класс Apex.

@isTest публичный класс NYRR_EquipmentRequestPageControllerTest {

@TestSetup static void TestSetupMethod () {

 User admin = [SELECT Id FROM User WHERE Profile.Name = 'System Administrator' and isActive = true and UserRoleId!='' LIMIT 1];

@isTest static void testMethod4 () {

  Account acc = [Select Id,Name from Account where Name = 'NYRR'];

   User u = [select id, Name,userName,Alias,lastname,ContactId from User where alias ='test1223'];
   Contact con = [SELECT Id,AccountId,FirstName,LastName,Email FROM Contact WHERE Id =:u.ContactId];

  user ExtUserObjFetch = [select id from user where FirstName= 'FirstNamePal' limit 1];


    //system.runAs(u){
      NYRR_EquipmentRequestPageController ClsObj = new NYRR_EquipmentRequestPageController();
      ClsObj.getRedirectToSiteDetails();
      ClsObj.userContact = con;
      ClsObj.accSwitcherSize = 1;
      ClsObj.concatenatedString = 'testStr';

      NYRR_EquipmentRequestPageController.rewardWrapper wrapObj = new NYRR_EquipmentRequestPageController.rewardWrapper();
      wrapObj.rewardName = 'test';
      wrapObj.isRequired = true;
      wrapObj.toolTip = 'testing';

      List<Account> aList = new List<Account>();

      account AccObj = TestDataFactory.getAccount();
       AccObj.OwnerId = ExtUserObjFetch.Id;
       aList.add(AccObj);

       account AccObj1 = TestDataFactory.getAccount();
       AccObj1.OwnerId = ExtUserObjFetch.Id;
       aList.add(AccObj1);


       account AccObj2 = TestDataFactory.getAccount();
       AccObj2.OwnerId = ExtUserObjFetch.Id;
      insert AccObj2; 

      contact ConObj =  TestDataFactory.getContact();
       ConObj.accountId = AccObj.id;
       ConObj.OwnerId = ExtUserObjFetch.Id;
       ConObj.Email = 'test123@testing.com';
       ConObj.LastName = 'testingLastName';
       insert ConObj; 

       Shipment_Package__c spObj= TestDataFactory.getShipmentPackage();
        Id ShipEquipRecTypeRT = Schema.SObjectType.Shipment_Package__c.getRecordTypeInfosByName().get('Equipment Request').getRecordTypeId();
        spObj.Name ='sp23';
        spObj.Shipment_Package_Type__c = 'Second Time Team Enrollment';
        spObj.Kit_SKU__c = 'testKITSKU123';
        spObj.RecordtypeId = ShipEquipRecTypeRT ;
        insert spObj;    

       YCS_Program_Type__c YCSProgObj = TestDataFactory.getYCS_ProgramType();
       YCSProgObj.Incentive_Model__c = spObj.id;
       YCSProgObj.Equipment_Request_Package__c = spObj.id;
       insert YCSProgObj;

       Application__c NewAppObj = [select name,program__c,program__r.Equipment_Request_Package__c from Application__c where name ='TestPalApplication'];
    Reward__c re = TestDataFactory.getReward();
    Id RewEquipRT = Schema.SObjectType.Reward__c.getRecordTypeInfosByName().get('Equipment').getRecordTypeId();
    re.RecordTypeId =RewEquipRT ;
    re.Name ='Shirt';
    insert re;       

    insert aList;

    List<Achievement__c> achivementList = new List<Achievement__c>();                                      
    Achievement__c a1 = TestDataFactory.getAchievement();
    a1.Name = 'Test123';             
    achivementList.add(a1);
    insert achivementList;    

     Document headerImg = [SELECT Id FROM Document WHERE DeveloperName = :Label.Email_Header_Document LIMIT 1];

    ClsObj.sendEmail(achivementList);

}
}

 public without sharing class ApexEmailTemplateRepository {

private static Document headerImg = [SELECT Id FROM Document WHERE DeveloperName = :Label.Email_Header_Document LIMIT 1];
private static Document footerImg = [SELECT Id FROM Document WHERE DeveloperName = :Label.Email_Footer_Document LIMIT 1];
private static String tableWidth = '550';
private static String commLabel = NYRR_Utility.isSandbox() ? '/STRIDES/' : '/';

public static String getSendEmailToPLTemplate(String plEmailId, String plFirstName, String plLastName, String contactFirstName, String contactLastName, String siteName){

    String htmlBody = ;


    String templateHtml = createHeader() + htmlBody + createFooter(plEmailId);
    return templateHTML;
}

public static String sendUsernameTouser(String uEmail, String uFirstName, String uLastName, String userName){
    String htmlBody = '';      

    String templateHtml = createHeader() + htmlBody + createFooter(uEmail);
    return templateHTML;
}

public static String createHeader(){

    String htmlHeader = 
        +               '<img src="' + URL.getSalesforceBaseUrl().toExternalForm() + commLabel + 'servlet/servlet.ImageServer?id=' + headerImg.Id + '&oid=' 
    return htmlHeader;
}

public static String createFooter(String sentToEmailId){

    String htmlFooter = 
        +               '<img src="' + URL.getSalesforceBaseUrl().toExternalForm() + commLabel + 'servlet/servlet.ImageServer?id=' + footerImg.Id +'&oid=' 
    return htmlFooter;
}

}

Я добавил тестовый класс и класс, в котором появляется ошибка. Мой охват кода составляет 69%. Нужно сделать его более 85.Помогите оценить. Не уверен насчет причины ошибки. Пожалуйста помоги. Заранее спасибо!

0 ответов

Другие вопросы по тегам