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
mat_tone_84mat_tone_84 

test class with many email doesn't work: Too many Email Invocations

I have a test class of a trigger with many if (exactly 12).

 

When I do "run test class" SF give me this error:

 

 

Too many Email Invocations: 11

 if I write this line, I solve the problem but I cannot test other "if" inside:

 

if (limits.getemailinvocations()> limits.getLimitEmailInvocations()){
if fieldX = y send email

if fieldz = w send email

if fieldk = e send email

...

}

How Can I test the last 3 if condition ??

Is there a way to reset limits.getemailinvocations and continue the test?

I try to do this but doesn't work 

limits.getemailinvocations() = null

 

The solution is create 2 trigger with 2 test class but it is for a beginner boy :)


 Thanks

 

 

 

 

SennahSennah

Matt,

 

you could write a test method for every 'if'-case.

You don't have to cover all possibilities in one method.

 

Hth,

Hannes

ascuccimarraascuccimarra

If writing more test methods is not an option (for whatever reason), you could try using Test.startTest() and Test.stopTest(), inside of this block you should get a new context of execution (meaning limits should get reset).

 

Hope this helps.

bouscalbouscal
Each test method can only call the Test.StartTest() method once so multiple test methods would be necessary.