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
Jim MontgomeryJim Montgomery 

error running test class but other test class runs fine.

Too many soql errors trigger msa data line 73

Getting error on this trigger fro one test class, but works fine from another test class.
trigger MSAData on Account (before insert,before update) {  
               Trigger

Map<String,String> MSALookup = new Map<String,String>();
  Set<String> AZipCode = new Set<String>();   
if(trigger.IsInsert){
 for(Account A:Trigger.new) {
    AZipCode.add(A.billingpostalcode);
 } 
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }    
    for(Account A:Trigger.new) {    
        AZipCode.add(A.billingpostalcode);
    }    
    for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
if(trigger.isUpdate){    
    for(Account acct:trigger.new){
        account oldAcct= Trigger.oldmap.get(Acct.Id);
    if (oldacct.BillingPostalCode<>Acct.BillingPostalCode){
        AZipCode.add(acct.billingpostalcode);
        } 
    }
    for(naics_code__c NA:
    [SELECT      zip_code__c, msa_name__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_name__c);
  }  
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_description__c = MSALookup.get(A.billingpostalcode);
      }
  }
    for(Account A:Trigger.new) {
            AZipCode.add(A.billingpostalcode);  
 } 
 for(naics_code__c NA:
    [SELECT      zip_code__c, msa_code__c
     FROM        naics_code__c
     WHERE       zip_code__c IN :AZipCode]) {
    MSALookup.put(NA.zip_code__c,NA.msa_code__c);
  }
  for(Account A:Trigger.new) {
      if(MSALookup.containsKey(A.billingpostalcode)) {
      A.d_B_msa_code__c = MSALookup.get(A.billingpostalcode);
      }
  }
}
}

Test Class
@isTest 
private class TestTaskEventRollup_RecordType {

    static testMethod void InsertTask() {

Account A = new Account(
            Name = 'myAcct', 
            BillingStreet='25 Upland Drive',
            BillingPostalCode='94127',
            BillingCountry='United States',
            BillingCity='San Francisco',
            recordtypeid = '012i0000000Ou0CAAS',
            software_owner__C = '005i0000001gISQAA2' );
        insert A;
       

Campaign Cam = new Campaign(
        name = '18--support-phone inbound-torrance',
        type = 'Direct mail',
        isactive = true);
        insert Cam;
        
 Contact c = new Contact(
        firstname = 'Jim', lastname = 'Montgomery');
        Insert c;

 Opportunity O = new Opportunity(
        Name = 'TestOpp',
        accountId = A.Id,
        type = 'New to Existing',
        Closedate = Date.today().addYears(1),
        stagename = '1. Gain Access',
        product_category__c = 'Med/Large Software',
        Amount = 1.00,
        product_Sub_Category__c = 'Tax');
        insert O;
        
       Task tsk = New Task(
Type = 'Email',
WhatId = A.Id,

Subject = 'Call'
);
insert tsk;

Task tsk2 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
insert tsk2;

Task tsk3 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
insert tsk3;
Event Evt = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Demo - Professional',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt;

Event Evt1 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Conference Call',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt1;

Event Evt2 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'In_Person Meeting',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
insert Evt2;
}
}
Raj VakatiRaj Vakati
Modify the test class as shown below 
 
@isTest 
private class TestTaskEventRollup_RecordType {

static testMethod void InsertTask() {

Account A = new Account(
		Name = 'myAcct', 
		BillingStreet='25 Upland Drive',
		BillingPostalCode='94127',
		BillingCountry='United States',
		BillingCity='San Francisco',
		recordtypeid = '012i0000000Ou0CAAS',
		software_owner__C = '005i0000001gISQAA2' );
	insert A;
   

Campaign Cam = new Campaign(
	name = '18--support-phone inbound-torrance',
	type = 'Direct mail',
	isactive = true);
	insert Cam;
	
Contact c = new Contact(
	firstname = 'Jim', lastname = 'Montgomery');
	Insert c;

Opportunity O = new Opportunity(
	Name = 'TestOpp',
	accountId = A.Id,
	type = 'New to Existing',
	Closedate = Date.today().addYears(1),
	stagename = '1. Gain Access',
	product_category__c = 'Med/Large Software',
	Amount = 1.00,
	product_Sub_Category__c = 'Tax');
	insert O;
	List<Task> ta= new List<Task>();
	
   Task tsk = New Task(
Type = 'Email',
WhatId = A.Id,

Subject = 'Call'
);
ta.add(tsk);

Task tsk2 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
ta.add(tsk2);

Task tsk3 = New Task(
Type = 'Email',
whatId = A.Id,
Subject = 'Call'
);
ta.add(tsk3);

insert ta ;
List<Event> evs = new List<Event>();
Event Evt = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Demo - Professional',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
evs.add(Evt);

Event Evt1 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'Conference Call',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
evs.add(Evt1);


Event Evt2 = New Event(
OwnerId = '005i0000001gISQAA2',
subject = 'Demonstration',
event_type__c = 'In_Person Meeting',
whatId = A.Id,
no_sa_needed__c = true,
startdatetime = datetime.newInstance(2018, 9, 15, 12, 30, 0),
enddatetime = datetime.newInstance(2018, 9, 15, 12, 35, 0));
evs.add(Evt2);

insert evs ; 

}
}

 
Jim MontgomeryJim Montgomery
Thanks you, but still getting too many soql queries error, this time on line 54.