function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TilluTillu 

System.Limit Exception : 101 Exception ??

Hii  I am getting System.Limit Exception. Please any one help me out....


public static Transaction__c GenTransactionAnnuity(Integer unique, String policyFieldVal, String CUSIP)
    {

      User annuityUser =                 TestFactory.CreateUser(10+unique, 'Annuity External Wholesaler', 'Mouse');
      User forecareUser =                 TestFactory.CreateUser(11+unique, 'Annuity External Wholesaler', 'Dragon');
      insert annuityUser;
      insert forecareUser;

      Territory__c Annuitory =        TestFactory.CreateTerritory(10+unique, annuityUser.Id, 'Annuity', '♣WA0', '98000', '99000', 'WA', 'Independent');
      Territory__c Forecaritory =     TestFactory.CreateTerritory(11+unique, forecareUser.Id, 'Forecare', '♣WA1', '', '', 'WA', 'Independent');
     
     
      insert Annuitory;    ///// Getting exception Too many soql querries...
    
     
      insert Forecaritory;
     

      Account IndependentAccount = TestFactory.CreateAccount(10+unique, 'rigid', 'Active', 'Independent');
      insert IndependentAccount;

      Contact A = GenContactAnnuity(0+unique, false, 'Independent');
        A.Annuity_Territory__c = Annuitory.Id;
        A.Exclude_from_Territory__c = true; //so the trigger

      Contact F = GenContactForecare(2+unique, false, 'Independent');
        F.Forecare_Territory__c = Forecaritory.Id;
        F.Exclude_from_Territory__c = true; //so the trigger   
        List<Contact> contacts = new List<Contact>();
        contacts.add(A);
        contacts.add(F);
        insert contacts;

      Map<Id, Contact> contactMap = new Map<Id, Contact>([SELECT Annuity_Territory__c, Forecare_Territory__c FROM Contact WHERE Id =: A.Id OR Id =: F.Id]);
        A = contactMap.get(A.Id);
        F = contactMap.get(F.Id);     

      contacts = new List<Contact>([SELECT Annuity_Territory__c, Forecare_Territory__c FROM Contact WHERE Id =: A.Id]); ///// Getting exception Too many soql querries...

      Policy__c annuityPolicy = TestFactory.CreatePolicy(10+unique, A.id, CUSIP);
     
     
      insert annuityPolicy;
Sujesh RamachandranSujesh Ramachandran
Hi Tillu,

Its not only the SOQL query you have used in the test methods counts aganist the governor limit but also all the soql query in the triggers of each object for you are inserting/updating. So you may have to finetune the triggers as well.

Also make sure to put the code to be tested inside Test.StartTest() and Test.StopTest(). Test.StartTest() will make sure that the governor limit will be reset after inserting the test data. 

Thanks,
Sujesh