I was getting too many soql queries, so decide to split the unit test. Now i am getting the error

variable doesn't exist:rtmap

public class test_createCaseFromOppt {
            public Map<String, Id> rtmap  = CommonUtilities.getRecordTypeNames('Opportunity');
                public Id recordTypeOpptPayroll = rtmap.get('Payroll');    

    static testMethod void myUnitTest1() {

      //  Id recordTypeOpptPayroll = rtmap.get('Payroll'); 
        Account account = new Account(BillingStreet='2510 Dixie Hwy. Ste. 8', BillingCity='Fort Mitchell',
                                      BillingState='KY', BillingCountry='USA',                  BillingPostalCode='41017', BillingCountryCode='US');

        account.Name = 'xyz';
        account.Source_System__c = 'abc';
        insert account; 

        system.debug('** 2: '+limits.getQueries());
        Opportunity oppt1 = new Opportunity();
        oppt1.Name = 'sample1';
        oppt1.AccountId = account.id;
        oppt1.RecordTypeId = recordTypeOpptPayroll;
        oppt1.StageName = 'Propose';
        oppt1.CloseDate = date.today().addYears(1);
        insert oppt1;
        oppt1.StageName = 'Closed Won';
        update oppt1;

 static testMethod void myUnitTest2() {............
  • 2
    BTW - There is almost no good reason as of V31 to need @isTest(SeeAllData=true) - your testmethods should create all the data needed to do assertions of correct behavior. You'll save yourself at deployment time
    – cropredy
    Sep 5, 2014 at 22:23

1 Answer 1


It looks like wherever you declared the rtmap either get split off, or you just never instantiate it unless I'm missing part of your code, because it looks like it had some issues being copy pasted.

I would also say, rather than splitting the test class out, to deal with the too many soql queries, to dig into your code base and figure out where that is coming from. Looking for queries in loops, unnecessary queries etc.


  • i edited my code, please look again.
    – user8132
    Sep 5, 2014 at 14:49
  • The trigger queries are not easy to fix, i tried and even wrote some methods to fix it, but it still is not fixed
    – user8132
    Sep 5, 2014 at 14:50
  • 2
    Test methods are static, whereas the variable you created is a class property. Try changing the variable to be static.
    – kcshafer
    Sep 5, 2014 at 14:50

Not the answer you're looking for? Browse other questions tagged .