You need to sign in to do that
Don't have an account?
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:
trigger AmountLimitCheck on Opportunity (Before insert) {
If(Trigger.IsInsert)
{
OpportunityAmountLimitCheck.Opportunity_records(trigger.new);
}
}
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> ();
{
Recepient.add('nikhilsomvanshi08@gmail.com');
}
sendmail.SetToAddresses(Recepient);
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.SetHTMLBody(emailbody);
sendmail.SetSubject('Opportunity Creation Error, Daily limit exceeded');
Messaging.SendEmailResult[] res = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {sendmail});
}
}
}
}
Please make sure this setting in setup.
If my answer helps resolve your query, please mark it as the 'Best Answer' & upvote it to benefit others.
Regards,
Kapil
(forcecube@gmail.com)
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.