+ Start a Discussion

Test Class Errors


I created 2 Classes (below) for testing purposes.  The first class creates an Account record, with 3 dummy user records that get populated into 3 custom user lookup fields on the Account.  The second class is a test class that is meant to cover a trigger that fires when the values for the users are changed on the Account.  Everything saves OK, but when I run the test, I get an error stating:

System.QueryException: List has no rows for assignment to SObject
Class.TestStatusAcctCreate.createAcct: line 6, column 1
Class.TestAccountPlan.testMyController1: line 9, column 1

Does anyone know why I would be getting this error?  Thanks.

public class TestStatusAcctCreate {

        // create and insert a new Accountrecord that has an arbitrary value for Type.
    public static Account createAcct(Integer i){ 

        Profile ProDir = [SELECT Id
                          FROM Profile
                          WHERE Name='Client Delivery (Director)'];
            User Dir1 = new User(Alias = 'DirUser',Country='United States',Email='DirUser@testing.com',EmailEncodingKey='UTF-8', LastName='Testing1', LanguageLocaleKey='en_US',LocaleSidKey='en_US',ProfileId = ProDir.Id,TimeZoneSidKey='America/New_York', UserName='DirUser@testing.com');
        insert Dir1;

        Profile ProTeamMgr = [SELECT Id
                              FROM Profile
                              WHERE Name='Client Delivery Team Manager'];
            User TM1 = new User(Alias = 'TMUser',Country='United States',Email='TMUser@testing.com',EmailEncodingKey='UTF-8', LastName='Testing2', LanguageLocaleKey='en_US',LocaleSidKey='en_US',ProfileId = ProTeamMgr.Id,TimeZoneSidKey='America/New_York', UserName='TMUser@testing.com');
        insert TM1;

        Profile ProCSM = [SELECT Id
                          FROM Profile
                          WHERE Name='Client Success Manager'];
            User CSM1 = new User(Alias = 'CSMUser',Country='United States',Email='CSMUser@testing.com',EmailEncodingKey='UTF-8', LastName='Testing3', LanguageLocaleKey='en_US',LocaleSidKey='en_US',ProfileId = ProCSM.Id,TimeZoneSidKey='America/New_York', UserName='CSMUser@testing.com');
        insert CSM1;

    Account acct = new Account();
            acct.Name = 'Test' + i;
            acct.Type= 'Employer';
            acct.Client_Advisor__c = CSM1.Id;
            acct.Industry_Manager__c = TM1.Id;
            acct.Market_Director__c = Dir1.Id;
        return acct;

public class TestAccountPlan {

public static testMethod void testMyController1() {    
    Account acct1 = TestGeneralAcctCreate.createAcct(0);
    insert acct1;

    Account acct2 = TestStatusAcctCreate.createAcct(0);
    insert acct2;

        Profile ProDir2 = [SELECT Id
                          FROM Profile
                          WHERE Name='Client Delivery (Director)'];
            User Dir2 = new User(Alias = 'Dir2User',Country='United States',Email='Dir2User@testing.com',EmailEncodingKey='UTF-8', LastName='Testing1a', LanguageLocaleKey='en_US',LocaleSidKey='en_US',ProfileId = ProDir2.Id,TimeZoneSidKey='America/New_York', UserName='Dir2User@testing.com');
        insert Dir2;

        Profile ProTeamMgr2 = [SELECT Id
                              FROM Profile
                              WHERE Name='Client Delivery Team Manager'];
            User TM2 = new User(Alias = 'TM2User',Country='United States',Email='TM2User@testing.com',EmailEncodingKey='UTF-8', LastName='Testing2a', LanguageLocaleKey='en_US',LocaleSidKey='en_US',ProfileId = ProTeamMgr2.Id,TimeZoneSidKey='America/New_York', UserName='TM2User@testing.com');
        insert TM2;

        Profile ProCSM2 = [SELECT Id
                          FROM Profile
                          WHERE Name='Client Success Manager'];
            User CSM2 = new User(Alias = 'CSM2User',Country='United States',Email='CSM2User@testing.com',EmailEncodingKey='UTF-8', LastName='Testing3a', LanguageLocaleKey='en_US',LocaleSidKey='en_US',ProfileId = ProCSM2.Id,TimeZoneSidKey='America/New_York', UserName='CSM2User@testing.com');
        insert CSM2;

        Account acct2a = [SELECT id,Market_Director__c,Industry_Manager__c,Client_Advisor__c
                          FROM Account
                          WHERE id =: acct2.Id];
               acct2a.Market_Director__c = Dir2.Id;
               acct2a.Industry_Manager__c = TM2.Id;
               acct2a.Client_Advisor__c = CSM2.Id;
    Account acct3 = TestGeneralAcctCreate.createAcct(0);
    insert acct3;

    Account acct4 = TestGeneralAcctCreate.createAcct(0);
    insert acct4;

    Account acct5 = TestGeneralAcctCreate.createAcct(0);
    insert acct5;

//    Account acct6 = TestStatusAcctCreate.createAcct(0);
//    insert acct6;

    Opportunity opp1 = TestOppCreate3.createOpp(acct1.Id);
    insert opp1;

    Contract_Summary__c contsumm1 = TestContractCreate.createContSumm(opp1.Id);
    insert contsumm1;
        Contract_Summary__c contSumm2 = [SELECT id
                                         FROM Contract_Summary__c
                                         WHERE id =: contSumm1.id];
    Client_Status_Scorecard__c cssc1 = TestStatusSCCreate.createCSSC1(acct1.Id);
    insert cssc1;
        Client_Status_Scorecard__c cssc1a = [SELECT id
                                           FROM Client_Status_Scorecard__c
                                           WHERE id =: cssc1.id];
    Client_Status_Scorecard__c cssc2 = TestStatusSCCreate.createCSSC2(acct2.Id);
    insert cssc2;
    Client_Status_Scorecard__c cssc3 = TestStatusSCCreate.createCSSC3(acct3.Id);
    insert cssc3;
    Client_Status_Scorecard__c cssc4 = TestStatusSCCreate.createCSSC4(acct4.Id);
    insert cssc4;
    Client_Status_Scorecard__c cssc5 = TestStatusSCCreate.createCSSC5(acct5.Id);
    insert cssc5;
//    Client_Status_Scorecard__c cssc6 = TestStatusSCCreate.createCSSC6(acct6.Id);
//    insert cssc6;
    Account_Plan__c plan1 = TestAcctPlanCreate.createAP1(acct1.Id);

    ApexPages.StandardController AcctPlan = new ApexPages.standardController(acct1);
    AcctPlanController APControl1 = new AcctPlanController(AcctPlan);
  //  APControl1.ap.add(plan1);
    APControl1.ap2 = plan1;
    update acct1;
    update acct2;
    update acct2a;
    update acct3;
    update acct4;
    update acct5;
//    update acct6;
    update opp1;
    update contsumm1;
    delete contsumm2;
    update cssc1;
//    update cssc2;
    update cssc3;
    update cssc4;
    update cssc5;
//    update cssc6;
    delete cssc1a;


Daniel B ProbertDaniel B Probert
is Client Delivery (Director) the name or Label?

didn't think ( )  are allowed in the api name.
I don't believe there is a label on Profiles.  I exported the records via Data Loader and it comes out as Client Delivery (Director) under Name.
Daniel B ProbertDaniel B Probert
on the first class have you got @Istest(SeeAllData=true)

if it's not in there then your test class won't be able to see it unless you create the profile as well.

i confused my self with recordtypes something i'm working on at the moment sorry.