+ Start a Discussion


Hi !


I have this trigger to send e-mail based on the field "e_mail__c":


trigger Email_EnviodeLayout_AR on Task (after update) {
  List<Id> TaskMap = new List<Id>();
    for(Task tsk : [select e_mail__c, subject, link_do_ar__c, status from Task])
        if(tsk.subject == 'AR - Envio do primeiro layout' && tsk.status == 'Concluído')
	        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
	        String[] toAddresses = new String[] {tsk.e_mail__c};
	        String template = 'Hello {0}, \nYour task has been modified. Here are the details - \n\n';
	        template+= 'Veja suas fotos clicando aqui - {1}\n';   
	        List<String> args = new List<String>();
	        // Here's the String.format() call.
	        String formattedHtml = String.format(template, args);
	        Messaging.SendEmail(new Messaging.SingleEmailMessage[] {mail});

 But It's giving me this error:


  • Email_EnviodeLayout_AR: execution of AfterUpdate caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: NO_MASS_MAIL_PERMISSION, Single email is not enabled for your organization or profile. Single email must be enabled for you to use this feature.: [] Trigger.Email_EnviodeLayout_AR: line 22, column 1
Best Answer chosen by Admin (Salesforce Developers) 

All Answers

Kiran  KurellaKiran Kurella


On a side note, it looks like this is an issue with your query. There is no where condition in the query, which means it will send an email for all tasks in the system and will run into governor limits down the road.


Try replacing the following line


for(Task tsk : [select e_mail__c, subject, link_do_ar__c, status from Task])




for(Task tsk : trigger.new)


If you need to query the database again then try this  


for(Task tsk : [select e_mail__c, subject, link_do_ar__c, status from Task where Id in : trigger.new])




Thanks CodeWizard, you are right too. 
I changed here.

Is there a way to add a "deliverability" check before the Messaging.SendEmail statement?

If System.Email.Deliverability something something?  :)