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
Nikhil SomvanshiNikhil Somvanshi 

Not able to receive any email even though the Program is saved successfully:

Hello All,

I have written a Trigger to abort creation of new opportunities at a certain condition and send an Email as a report to the admin. I am using a helper class-method to implement this. The trigger works fine (Aborts the process successfully), but i am not able to receive the email, even though the program saves without an error. Please take a quick look at my code:


trigger AmountLimitCheck on Opportunity (Before insert) {



Helper Class:

Public class OpportunityAmountLimitCheck

Public static void Opportunity_records(List <Opportunity> ops)
double Amount_op = 0;

    for(Opportunity op:[select Amount from Opportunity where CreatedDate = today])
    Amount_op = Amount_op + op.Amount ;
    for (Opportunity o: ops)
    Amount_op = Amount_op + o.Amount;
        If (Amount_op > 100000)
        o.addError('Daily Opportunity Amount limit exceeded');
        Messaging.SingleEmailMessage sendmail = new Messaging.SingleEmailMessage();
        List<String> Recepient= new List <String> ();
        String emailbody = 'Dear ' +o.OwnerId ;
                          emailbody += 'Please note that your opportunities has reached daily limit.';
                          emailbody += 'You will now be restricted from creating any more opportunities';
        sendmail.SetSubject('Opportunity Creation Error, Daily limit exceeded');
        Messaging.SendEmailResult[] res = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {sendmail});


Hi Nikhil,

Please make sure this setting in setup.
User-added image

If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.

Nikhil SomvanshiNikhil Somvanshi

Hi Kapil,

Thanks for your time and reply. As you suggested, i checked the Access Level of my Org and it is well-settled on All email.