You need to sign in to do that
Don't have an account?
Force.platform
System.EmailException:
i have trigger to send email to user after record inserted. but there is error:
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger customerTrigger caused an unexpected exception, contact your administrator: customerTrigger: execution of AfterInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Email body is required.: []: Class.CustomerImpl.sendEmailToCustomer: line 11, column 1
Trigger:
trigger customerTrigger on Customer__c (after insert, after update) {
List<Customer__C> cust=[select name, Email_Address__c,Comment__C from Customer__C];
for(Customer__C ct:cust)
{CustomerImpl c=new CustomerImpl();
c.sendEmailToCustomer();
}
}
class:
public class CustomerImpl {
public void sendEmailToCustomer()
{
Customer__C cust=new Customer__C();
Messaging.SingleEmailMessage msg= new Messaging.SingleEmailMessage();
msg.setToAddresses(new String[]{Cust.Email_Address__c});
msg.setSubject('info about session');
msg.setPlainTextBody(cust.comment__c);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{msg});
}
}
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger customerTrigger caused an unexpected exception, contact your administrator: customerTrigger: execution of AfterInsert caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Email body is required.: []: Class.CustomerImpl.sendEmailToCustomer: line 11, column 1
Trigger:
trigger customerTrigger on Customer__c (after insert, after update) {
List<Customer__C> cust=[select name, Email_Address__c,Comment__C from Customer__C];
for(Customer__C ct:cust)
{CustomerImpl c=new CustomerImpl();
c.sendEmailToCustomer();
}
}
class:
public class CustomerImpl {
public void sendEmailToCustomer()
{
Customer__C cust=new Customer__C();
Messaging.SingleEmailMessage msg= new Messaging.SingleEmailMessage();
msg.setToAddresses(new String[]{Cust.Email_Address__c});
msg.setSubject('info about session');
msg.setPlainTextBody(cust.comment__c);
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{msg});
}
}
In the above code, you are creating a new instance of Customer class and referencing it below lines to set the value of setToAddresses,setPlainTextBody but the value of the instance of Customer__C will be null as you have not set the object. Hence you are getting the error.
A crude solution for your problem can be as below