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
ashishrai4uashishrai4u 

Not able to Achieve required coverage of a Trigger having nested If else conditions.

I have a trigger which having nested  if and else conditions.If i use more DML  soql then i am reaching  the governor limit. I have only covered only 40%.So is there any alternative  way of testmethod to cover Trigger coverage . Below is the sample code of trigger.Please help me its very urgent.

 

 

If(E.whoid==Eold.whoid)  
{    
 if(Unew[0].FirstName=='Abhey')
          {
              if(Tnew.size()>0)
                {
                      if(EO1.size()>0)
                             { 
                                    if(Uold[0].FirstName=='Heather')
                                     {
                                        
                                         if(Told.size()>0) 
                                             {
                                                   if(EO2.size()>0)
                                                    {
                                                    
                                                            if(EO2[0].ActivityDate >= Told[0].ActivityDate)
                                                                  {
                                                                 
                                                                 }
                                                            else
                                                                {
                                                         
                                                                }
                                                }

Thanks.

 

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

You can write more than one method in Test Class so in one method you can write up to 20 DML statements and since this test method needs more than 20 DML statements so you create another method. There is no limit on number of methods and number of lines in a test method so you will never hit the governor limit by this way.

 

Find below a sample code -

 

                @isTest

                private class MyTestClass

                {

                                static testmethod void MyTestMethod1()

                                {

                                                // here write your code up to 20 DML

                                }

                                static testmethod void MyTestMethod2()

                                {

                                                // here write your code up to 20 DML

                                }

                                static testmethod void MyTestMethod3()

                                {

                                                // here write your code up to 20 DML

                                }

                }

All Answers

kyle.tkyle.t

You should probably post the entire tirgger and the test method you have written.

Pradeep_NavatarPradeep_Navatar

You can write more than one method in Test Class so in one method you can write up to 20 DML statements and since this test method needs more than 20 DML statements so you create another method. There is no limit on number of methods and number of lines in a test method so you will never hit the governor limit by this way.

 

Find below a sample code -

 

                @isTest

                private class MyTestClass

                {

                                static testmethod void MyTestMethod1()

                                {

                                                // here write your code up to 20 DML

                                }

                                static testmethod void MyTestMethod2()

                                {

                                                // here write your code up to 20 DML

                                }

                                static testmethod void MyTestMethod3()

                                {

                                                // here write your code up to 20 DML

                                }

                }

This was selected as the best answer