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
Darlene BlaneyDarlene Blaney 

Too many SOQL queries: 101 Simple Test Class

Hi all,

I have a simple trigger and class that recalculates a SAT recentered score.  The trigger works great, but I am having an issue with the test class.  Because there are so many possibilities, the best I can achieve is 50% coverage and I'm concerned about not being able to install into production.  I am including the test class for your viewing.  Any help would be greatly appreciated.

@isTest
private class ContactSATRecenteredTest {
    
    static testMethod void myUnitTest() {
        
        test.startTest();
        
        ContactSATRecentered controller = new ContactSATRecentered();
        
        Contact con = new Contact();
        Contact con1 = new Contact();
        Test_Score__c tst = new Test_Score__c();
        Test_Score__c tst1 = new Test_Score__c();
        
        con.FirstName = 'TestScore';
        con.LastName = 'NewTest';
        insert con;
        tst.Contact__c = con.Id;
        tst.SAT_Evidence_Reading_Writing_Section__c = 800;
        tst.SAT_Math_Section_R__c = 800;
        insert tst;
        
        // Retrieve the new contact 36
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 800;
        tst.SAT_Math_Section_R__c = 790;
        update tst;
        
        // Retrieve the new contact 35
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 800;
        tst.SAT_Math_Section_R__c = 750;
        update tst;
        
        // Retrieve the new contact 34
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 800;
        tst.SAT_Math_Section_R__c = 730;
        update tst;
        
        // Retrieve the new contact 33
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 800;
        tst.SAT_Math_Section_R__c = 690;
        update tst;
        
        // Retrieve the new contact 32
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 800;
        tst.SAT_Math_Section_R__c = 660;
        update tst;
        
        // Retrieve the new contact 31
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 700;
        tst.SAT_Math_Section_R__c = 700;
        update tst;
        
        // Retrieve the new contact 30
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 700;
        tst.SAT_Math_Section_R__c = 690;
        update tst;
        
        // Retrieve the new contact 29
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 700;
        tst.SAT_Math_Section_R__c = 630;
        update tst;
        
        // Retrieve the new contact 28
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 700;
        tst.SAT_Math_Section_R__c = 600;
        update tst;
        
        // Retrieve the new contact 27
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 700;
        tst.SAT_Math_Section_R__c = 580;
        update tst;
        
        // Retrieve the new contact 26
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 700;
        tst.SAT_Math_Section_R__c = 530;
        update tst;
        
        // Retrieve the new contact 25
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 600;
        tst.SAT_Math_Section_R__c = 590;
        update tst;
        
        // Retrieve the new contact 24
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 600;
        tst.SAT_Math_Section_R__c = 560;
        update tst;
        
        // Retrieve the new contact 23
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 600;
        tst.SAT_Math_Section_R__c = 530;
        update tst;
        
        // Retrieve the new contact 22
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 600;
        tst.SAT_Math_Section_R__c = 500;
        update tst;
        
        // Retrieve the new contact 21
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 500;
        tst.SAT_Math_Section_R__c = 560;
        update tst;
        
        // Retrieve the new contact 20
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 500;
        tst.SAT_Math_Section_R__c = 500;
        update tst;
        
        // Retrieve the new contact 19
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 500;
        tst.SAT_Math_Section_R__c = 460;
        update tst;
        
        // Retrieve the new contact 18
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 500;
        tst.SAT_Math_Section_R__c = 420;
        update tst;
        
        // Retrieve the new contact 17
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 500;
        tst.SAT_Math_Section_R__c = 400;
        update tst;
        
        // Retrieve the new contact 16
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 400;
        tst.SAT_Math_Section_R__c = 450;
        update tst;
        
        // Retrieve the new contact 15
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 400;
        tst.SAT_Math_Section_R__c = 400;
        update tst;
        
        // Retrieve the new contact 14
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        //tst.SAT_Evidence_Reading_Writing_Section__c = 400;
        //tst.SAT_Math_Section_R__c = 350;
        //update tst;
        
        // Retrieve the new contact 13
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        //tst.SAT_Evidence_Reading_Writing_Section__c = 400;
        //tst.SAT_Math_Section_R__c = 300;
        //update tst;
        
        // Retrieve the new contact 12
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
               
        tst.SAT_Evidence_Reading_Writing_Section__c = 400;
        tst.SAT_Math_Section_R__c = 250;
        update tst;
        
        // Retrieve the new contact 11
        //con = [select SAT_Super_Score_Recentered__c from contact where id = :con.id];
        
        con1.FirstName = 'TestScore';
        con1.LastName = 'OldTest';
        insert con1;
        tst1.Contact__c = con1.Id;
        tst1.SAT_Critical_Reading__c = 800;
        tst1.SAT_Math__c = 800;
        insert tst1;
        
        // Retrieve the new contact 36
        //con1 = [select SAT_Super_Score_Recentered__c from contact where id = :con1.id];
        
        tst1.SAT_Evidence_Reading_Writing_Section__c = 800;
        tst1.SAT_Math_Section_R__c = 780;
        update tst1;
        
        // Retrieve the new contact 35
        //con1 = [select SAT_Super_Score_Recentered__c from contact where id = :con1.id];
        
        tst1.SAT_Evidence_Reading_Writing_Section__c = 800;
        tst1.SAT_Math_Section_R__c = 720;
        update tst1;
        
        // Retrieve the new contact 34
        //con1 = [select SAT_Super_Score_Recentered__c from contact where id = :con1.id];
        
        tst1.SAT_Evidence_Reading_Writing_Section__c = 700;
        tst1.SAT_Math_Section_R__c = 770;
        update tst1;
        
        // Retrieve the new contact 33
        //con1 = [select SAT_Super_Score_Recentered__c from contact where id = :con1.id];
        
        tst1.SAT_Evidence_Reading_Writing_Section__c = 700;
        tst1.SAT_Math_Section_R__c = 720;
        update tst1;
        
        // Retrieve the new contact 32
        //con1 = [select SAT_Super_Score_Recentered__c from contact where id = :con1.id];
        
        //tst1.SAT_Evidence_Reading_Writing_Section__c = 700;
        //tst1.SAT_Math_Section_R__c = 680;
        //update tst1;
        
        // Retrieve the new contact 31
        //con1 = [select SAT_Super_Score_Recentered__c from contact where id = :con1.id];
        
        //tst1.SAT_Evidence_Reading_Writing_Section__c = 700;
        //tst1.SAT_Math_Section_R__c = 640;
        //update tst1;
        
        // Retrieve the new contact 30
        //con1 = [select SAT_Super_Score_Recentered__c from contact where id = :con1.id];
        
        //tst1.SAT_Evidence_Reading_Writing_Section__c = 700;
        //tst1.SAT_Math_Section_R__c = 600;
        //update tst1;
        
        // Retrieve the new contact 29
        //con1 = [select SAT_Super_Score_Recentered__c from contact where id = :con1.id];
        
        //tst1.SAT_Evidence_Reading_Writing_Section__c = 600;
        //tst1.SAT_Math_Section_R__c = 670;
        //update tst1;
        
        // Retrieve the new contact 28
        //con1 = [select SAT_Super_Score_Recentered__c from contact where id = :con1.id];
        
        tst1.SAT_Evidence_Reading_Writing_Section__c = 600;
        tst1.SAT_Math_Section_R__c = 630;
        update tst1;
        
        // Retrieve the new contact 27
        //con1 = [select SAT_Super_Score_Recentered__c from contact where id = :con1.id];

        test.stopTest();
                
    }

}
Best Answer chosen by Darlene Blaney
Amit Chaudhary 8Amit Chaudhary 8
Please try below code.
@isTest
private class ContactSATRecenteredTest 
{
    static testMethod void myUnitTest() 
	{
        Contact con = new Contact( );
			con.FirstName = 'TestScore' ;
			con.LastName = 'NewTest';
		insert con;

        Test_Score__c tst = new Test_Score__c();
			tst.Contact__c = con.Id;
			tst.SAT_Evidence_Reading_Writing_Section__c = 200;
			tst.SAT_Math_Section_R__c = 200;
        insert tst;

		
        Contact con1 = new Contact();
			con1.FirstName = 'TestScore';
			con1.LastName = 'OldTest';
		insert con1;
		
        Test_Score__c tst1 = new Test_Score__c();
			tst1.Contact__c = con1.Id;
			tst1.SAT_Critical_Reading__c = 200;
			tst1.SAT_Math__c = 200;
        insert tst1;

		List<Contact> listCont = new List<Contact>();
		listCont.add(con);
		listCont.add(con1);

		update listCont;
        
        test.startTest();

			
			tst1.SAT_Math__c = 500;
			tst.SAT_Math_Section_R__c = 500;

			List<Test_Score__c> lstScore = new List<Test_Score__c>();
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;

			update listCont;

			lstScore.clear();
			tst1.SAT_Math__c = 600;
			tst.SAT_Math_Section_R__c = 600;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;

			update listCont;
			

			lstScore.clear();
			tst1.SAT_Math__c = 700;
			tst.SAT_Math_Section_R__c = 700;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;

			update listCont;

			lstScore.clear();
			tst1.SAT_Math__c = 800;
			tst.SAT_Math_Section_R__c = 800;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;

			update listCont;
			
			lstScore.clear();
			tst1.SAT_Math__c = 900;
			tst.SAT_Math_Section_R__c = 900;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;
			update listCont;

			lstScore.clear();
			tst1.SAT_Math__c = 1000;
			tst.SAT_Math_Section_R__c = 1000;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;
			update listCont;
			// update further code coverage like above

			test.stopTest();
                
    }

}
Let us know if this will help you
 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
You are doing to many DML in your test class. It will better if you will use List to perform DML/

I hope you are writing test class for "ContactSATRecentered" class. PLease post same class so that we can help you
Darlene BlaneyDarlene Blaney
Hi Amit,

It wouldn't let me post both at the same time.  Here is the class:
public class ContactSATRecentered {
/***************
 * When an Admissions Contact is created or updated, need to evaluate the 
 * information provided to determine if SAT scores are entered and need to be 
 * recentered.
****************/
    
    public static void setSATRecentered(Contact[] contacts){
        
        for (Contact co:contacts){
            if (co.SAT_Super_Score__c != NULL && co.SAT_Super_Score__c <> 0) {
                if (co.Best_SAT_ERW_Section_R__c != NULL && co.Best_SAT_Math_Section_R__c != NULL){
                if (co.SAT_Super_Score__c == 1600) {
                    co.SAT_Super_Score_Recentered__c = 36;
                } else if (co.SAT_Super_Score__c < 1600 && co.SAT_Super_Score__c >= 1570) {
                    co.SAT_Super_Score_Recentered__c = 35;
                } else if (co.SAT_Super_Score__c < 1570 && co.SAT_Super_Score__c >= 1540) {
                    co.SAT_Super_Score_Recentered__c = 34;
                } else if (co.SAT_Super_Score__c < 1540 && co.SAT_Super_Score__c >= 1500) {
                    co.SAT_Super_Score_Recentered__c = 33;
                } else if (co.SAT_Super_Score__c < 1500 && co.SAT_Super_Score__c >= 1470) {
                    co.SAT_Super_Score_Recentered__c = 32;
                } else if (co.SAT_Super_Score__c < 1470 && co.SAT_Super_Score__c >= 1430) {
                    co.SAT_Super_Score_Recentered__c = 31;
                } else if (co.SAT_Super_Score__c < 1430 && co.SAT_Super_Score__c >= 1400) {
                    co.SAT_Super_Score_Recentered__c = 30;
                } else if (co.SAT_Super_Score__c < 1400 && co.SAT_Super_Score__c >= 1360) {
                    co.SAT_Super_Score_Recentered__c = 29;
                } else if (co.SAT_Super_Score__c < 1360 && co.SAT_Super_Score__c >= 1320) {
                    co.SAT_Super_Score_Recentered__c = 28;
                } else if (co.SAT_Super_Score__c < 1320 && co.SAT_Super_Score__c >= 1290) {
                    co.SAT_Super_Score_Recentered__c = 27;
                } else if (co.SAT_Super_Score__c < 1290 && co.SAT_Super_Score__c >= 1260) {
                    co.SAT_Super_Score_Recentered__c = 26;
                } else if (co.SAT_Super_Score__c < 1260 && co.SAT_Super_Score__c >= 1220) {
                    co.SAT_Super_Score_Recentered__c = 25;
                } else if (co.SAT_Super_Score__c < 1220 && co.SAT_Super_Score__c >= 1180) {
                    co.SAT_Super_Score_Recentered__c = 24;
                } else if (co.SAT_Super_Score__c < 1180 && co.SAT_Super_Score__c >= 1140) {
                    co.SAT_Super_Score_Recentered__c = 23;
                } else if (co.SAT_Super_Score__c < 1140 && co.SAT_Super_Score__c >= 1110) {
                    co.SAT_Super_Score_Recentered__c = 22;
                } else if (co.SAT_Super_Score__c < 1110 && co.SAT_Super_Score__c >= 1070) {
                    co.SAT_Super_Score_Recentered__c = 21;
                } else if (co.SAT_Super_Score__c < 1070 && co.SAT_Super_Score__c >= 1030) {
                    co.SAT_Super_Score_Recentered__c = 20;
                } else if (co.SAT_Super_Score__c < 1030 && co.SAT_Super_Score__c >= 990) {
                    co.SAT_Super_Score_Recentered__c = 19;
                } else if (co.SAT_Super_Score__c < 990 && co.SAT_Super_Score__c >= 950) {
                    co.SAT_Super_Score_Recentered__c = 18;
                } else if (co.SAT_Super_Score__c < 950 && co.SAT_Super_Score__c >= 910) {
                    co.SAT_Super_Score_Recentered__c = 17;
                } else if (co.SAT_Super_Score__c < 910 && co.SAT_Super_Score__c >= 870) {
                    co.SAT_Super_Score_Recentered__c = 16;
                } else if (co.SAT_Super_Score__c < 870 && co.SAT_Super_Score__c >= 830) {
                    co.SAT_Super_Score_Recentered__c = 15;
                } else if (co.SAT_Super_Score__c < 830 && co.SAT_Super_Score__c >= 780) {
                    co.SAT_Super_Score_Recentered__c = 14;
                } else if (co.SAT_Super_Score__c < 780 && co.SAT_Super_Score__c >= 740) {
                    co.SAT_Super_Score_Recentered__c = 13;
                } else if (co.SAT_Super_Score__c < 740 && co.SAT_Super_Score__c >= 680) {
                    co.SAT_Super_Score_Recentered__c = 12;
                } else if (co.SAT_Super_Score__c < 680 && co.SAT_Super_Score__c >= 590) {
                    co.SAT_Super_Score_Recentered__c = 11;
                } else if (co.SAT_Super_Score__c < 590) {
                    co.SAT_Super_Score_Recentered__c = 10;
                }
                } /* If new SAT scores */
                else if (co.Best_SAT_Critical_Reading__c != NULL && co.Best_SAT_Math__c != NULL) {
                    if (co.SAT_Super_Score__c == 1600) {
                        co.SAT_Super_Score_Recentered__c = 36;
                    } else if (co.SAT_Super_Score__c < 1600 && co.SAT_Super_Score__c >= 1540) {
                        co.SAT_Super_Score_Recentered__c = 35;
                    } else if (co.SAT_Super_Score__c < 1540 && co.SAT_Super_Score__c >= 1490) {
                        co.SAT_Super_Score_Recentered__c = 34;
                    } else if (co.SAT_Super_Score__c < 1490 && co.SAT_Super_Score__c >= 1440) {
                        co.SAT_Super_Score_Recentered__c = 33;
                    } else if (co.SAT_Super_Score__c < 1440 && co.SAT_Super_Score__c >= 1400) {
                        co.SAT_Super_Score_Recentered__c = 32;
                    } else if (co.SAT_Super_Score__c < 1400 && co.SAT_Super_Score__c >= 1360) {
                        co.SAT_Super_Score_Recentered__c = 31;
                    } else if (co.SAT_Super_Score__c < 1360 && co.SAT_Super_Score__c >= 1330) {
                        co.SAT_Super_Score_Recentered__c = 30;
                    } else if (co.SAT_Super_Score__c < 1330 && co.SAT_Super_Score__c >= 1290) {
                        co.SAT_Super_Score_Recentered__c = 29;
                    } else if (co.SAT_Super_Score__c < 1290 && co.SAT_Super_Score__c >= 1250) {
                        co.SAT_Super_Score_Recentered__c = 28;
                    } else if (co.SAT_Super_Score__c < 1250 && co.SAT_Super_Score__c >= 1210) {
                        co.SAT_Super_Score_Recentered__c = 27;
                    } else if (co.SAT_Super_Score__c < 1210 && co.SAT_Super_Score__c >= 1170) {
                        co.SAT_Super_Score_Recentered__c = 26;
                    } else if (co.SAT_Super_Score__c < 1170 && co.SAT_Super_Score__c >= 1130) {
                        co.SAT_Super_Score_Recentered__c = 25;
                    } else if (co.SAT_Super_Score__c < 1130 && co.SAT_Super_Score__c >= 1090) {
                        co.SAT_Super_Score_Recentered__c = 24;
                    } else if (co.SAT_Super_Score__c < 1090 && co.SAT_Super_Score__c >= 1050) {
                        co.SAT_Super_Score_Recentered__c = 23;
                    } else if (co.SAT_Super_Score__c < 1050 && co.SAT_Super_Score__c >= 1020) {
                        co.SAT_Super_Score_Recentered__c = 22;
                    } else if (co.SAT_Super_Score__c < 1020 && co.SAT_Super_Score__c >= 980) {
                        co.SAT_Super_Score_Recentered__c = 21;
                    } else if (co.SAT_Super_Score__c < 980 && co.SAT_Super_Score__c >= 940) {
                        co.SAT_Super_Score_Recentered__c = 20;
                    } else if (co.SAT_Super_Score__c < 940 && co.SAT_Super_Score__c >= 900) {
                        co.SAT_Super_Score_Recentered__c = 19;
                    } else if (co.SAT_Super_Score__c < 900 && co.SAT_Super_Score__c >= 860) {
                        co.SAT_Super_Score_Recentered__c = 18;
                    } else if (co.SAT_Super_Score__c < 860 && co.SAT_Super_Score__c >= 820) {
                        co.SAT_Super_Score_Recentered__c = 17;
                    } else if (co.SAT_Super_Score__c < 820 && co.SAT_Super_Score__c >= 770) {
                        co.SAT_Super_Score_Recentered__c = 16;
                    } else if (co.SAT_Super_Score__c < 770 && co.SAT_Super_Score__c >= 720) {
                        co.SAT_Super_Score_Recentered__c = 15;
                    } else if (co.SAT_Super_Score__c < 720 && co.SAT_Super_Score__c >= 670) {
                        co.SAT_Super_Score_Recentered__c = 14;
                    } else if (co.SAT_Super_Score__c < 670 && co.SAT_Super_Score__c >= 620) {
                        co.SAT_Super_Score_Recentered__c = 13;
                    } else if (co.SAT_Super_Score__c < 620 && co.SAT_Super_Score__c >= 560) {
                        co.SAT_Super_Score_Recentered__c = 12;
                    } else if (co.SAT_Super_Score__c < 560 && co.SAT_Super_Score__c >= 510) {
                        co.SAT_Super_Score_Recentered__c = 11;
                    } else if (co.SAT_Super_Score__c < 510) {
                        co.SAT_Super_Score_Recentered__c = 10;
                    }
                } /* If old SAT scores */
                    
            } /* If SuperScore not null and not 0 */
        } /* For loop */
    }
}
Darlene BlaneyDarlene Blaney
This is  a contact trigger.  The 4 contact fields used are formula fields that get their values from Test_Score__c.  Therefore, to impact the Contact fields, I have to populate the Test_Score__c.
Darlene BlaneyDarlene Blaney
The code above works (my original code works too), but your code only provides 7% code coverage.  My version provides 50%.  It is my understanding that we should try and cover at least 75%.
Darlene BlaneyDarlene Blaney
Here are all the fields that impact this process:

SAT_Super_Score__c:
IF((Best_SAT_Critical_Reading__c + Best_SAT_Math__c) <> 0,Ceiling((Best_SAT_Critical_Reading__c + Best_SAT_Math__c)), IF(( Best_SAT_ERW_Section_R__c + Best_SAT_Math_Section_R__c ) <> 0,Ceiling(( Best_SAT_ERW_Section_R__c + Best_SAT_Math_Section_R__c )),0) 
)

Best_SAT_Critical_Reading__c:
Roll-up Summary - MAX(Test_Score__c.SAT_Critical_Reading__c)

Best_SAT_Math__c:
Roll-up Summary - MAX(Test_Score__c.SAT_Math__c)

Best_SAT_ERW_Section_R__c:
Roll-up Summary - MAX(SAT_Evidence_Reading_Writing_Section__c)

Best_SAT_Math_Section_R__c:
Roll-up Summary - MAX(SAT_Math_Section_R__c)
Amit Chaudhary 8Amit Chaudhary 8
Please try below test class.
@isTest
private class ContactSATRecenteredTest 
{
    static testMethod void myUnitTest() 
	{
        Contact con = new Contact( );
			con.FirstName = 'TestScore' ;
			con.LastName = 'NewTest';
		insert con;

        Test_Score__c tst = new Test_Score__c();
			tst.Contact__c = con.Id;
			tst.SAT_Evidence_Reading_Writing_Section__c = 200;
			tst.SAT_Math_Section_R__c = 200;
        insert tst;

		
        Contact con1 = new Contact();
			con1.FirstName = 'TestScore';
			con1.LastName = 'OldTest';
		insert con1;
		
        Test_Score__c tst1 = new Test_Score__c();
			tst1.Contact__c = con1.Id;
			tst1.SAT_Critical_Reading__c = 200;
			tst1.SAT_Math__c = 200;
        insert tst1;

        
        test.startTest();

			List<Contact> listCont = new List<Contact>();
			listCont.add(con);
			listCont.add(con1);

			update listCont;
			
			tst1.SAT_Math__c = 700;
			tst.SAT_Math_Section_R__c = 700;

			List<Test_Score__c> lstScore = new List<Test_Score__c>();
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;

			update listCont;

			lstScore.clear();
			tst1.SAT_Math__c = 900;
			tst.SAT_Math_Section_R__c = 900;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;

			update listCont;
			
						
        test.stopTest();
                
    }

}
Let us know if this will help you

Thanks
Amit Chaudhary
 
Darlene BlaneyDarlene Blaney
Hi Amit,

I think you are on to something.  I am up to 57% code coverage.  How many more scenarios can I add before I would hit the limit?
Amit Chaudhary 8Amit Chaudhary 8
Please try below code.
@isTest
private class ContactSATRecenteredTest 
{
    static testMethod void myUnitTest() 
	{
        Contact con = new Contact( );
			con.FirstName = 'TestScore' ;
			con.LastName = 'NewTest';
		insert con;

        Test_Score__c tst = new Test_Score__c();
			tst.Contact__c = con.Id;
			tst.SAT_Evidence_Reading_Writing_Section__c = 200;
			tst.SAT_Math_Section_R__c = 200;
        insert tst;

		
        Contact con1 = new Contact();
			con1.FirstName = 'TestScore';
			con1.LastName = 'OldTest';
		insert con1;
		
        Test_Score__c tst1 = new Test_Score__c();
			tst1.Contact__c = con1.Id;
			tst1.SAT_Critical_Reading__c = 200;
			tst1.SAT_Math__c = 200;
        insert tst1;

		List<Contact> listCont = new List<Contact>();
		listCont.add(con);
		listCont.add(con1);

		update listCont;
        
        test.startTest();

			
			tst1.SAT_Math__c = 500;
			tst.SAT_Math_Section_R__c = 500;

			List<Test_Score__c> lstScore = new List<Test_Score__c>();
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;

			update listCont;

			lstScore.clear();
			tst1.SAT_Math__c = 600;
			tst.SAT_Math_Section_R__c = 600;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;

			update listCont;
			

			lstScore.clear();
			tst1.SAT_Math__c = 700;
			tst.SAT_Math_Section_R__c = 700;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;

			update listCont;

			lstScore.clear();
			tst1.SAT_Math__c = 800;
			tst.SAT_Math_Section_R__c = 800;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;

			update listCont;
			
			lstScore.clear();
			tst1.SAT_Math__c = 900;
			tst.SAT_Math_Section_R__c = 900;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;
			update listCont;

			lstScore.clear();
			tst1.SAT_Math__c = 1000;
			tst.SAT_Math_Section_R__c = 1000;
			lstScore.add(tst1);
			lstScore.add(tst);
			update lstScore;
			update listCont;
			// update further code coverage like above

			test.stopTest();
                
    }

}
Let us know if this will help you
 
This was selected as the best answer
Darlene BlaneyDarlene Blaney
I was able to get the coverage to 79% before I hit the SOQL limit - that should be good enough.

Thank you SO much for all your help with this!!!