You need to sign in to do that
Don't have an account?
Variable does not exist: EmailManager
Dear Friends,
Can Anyone explain Why this error was showing here ...
trigger ExampleTrigger on Contact (after insert, after delete) {
if (Trigger.isInsert) {
Integer recordCount = Trigger.New.size();
// Call a utility method from another class
EmailManager.sendMail('Your email address', 'Trailhead Trigger Tutorial',
recordCount + ' contact(s) were inserted.');
}
else if (Trigger.isDelete) {
// Process after delete
}
}
Error : Variable does not exist: EmailManager
Thanks In Advance ..
Can Anyone explain Why this error was showing here ...
trigger ExampleTrigger on Contact (after insert, after delete) {
if (Trigger.isInsert) {
Integer recordCount = Trigger.New.size();
// Call a utility method from another class
EmailManager.sendMail('Your email address', 'Trailhead Trigger Tutorial',
recordCount + ' contact(s) were inserted.');
}
else if (Trigger.isDelete) {
// Process after delete
}
}
Error : Variable does not exist: EmailManager
Thanks In Advance ..
Please try changing the sendMail method signature to :
public static void sendMail(String address, String subject, String body)
If you have to invoke a method (from trigger in your case) without instantiating an object, it should be defined as Static.
If you dont want to define it as Static, please create an instance (object) for the class EmailManager and then invoke the method sentMail.
Eg:
EmailManager obj = new EmailManager();
obj.sendMail('Your email address', 'Trailhead Trigger Tutorial',
recordCount + ' contact(s) were inserted.');
Hope this helps.
Please mark it as solved if it answers your question.
All Answers
I realised My Mistakes here .. there is no class with a name of EmailManager Now i have saved This class as below...
=========================================================================
public class EmailManager {
// Public method
public void sendMail(String address, String subject, String body) {
// Create an email message object
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {address};
mail.setToAddresses(toAddresses);
mail.setSubject(subject);
mail.setPlainTextBody(body);
// Pass this email message to the built-in sendEmail method
// of the Messaging class
Messaging.SendEmailResult[] results = Messaging.sendEmail(
new Messaging.SingleEmailMessage[] { mail });
// Call a helper method to inspect the returned results
inspectResults(results);
}
// Helper method
private static Boolean inspectResults(Messaging.SendEmailResult[] results) {
Boolean sendResult = true;
// sendEmail returns an array of result objects.
// Iterate through the list to inspect results.
// In this class, the methods send only one email,
// so we should have only one result.
for (Messaging.SendEmailResult res : results) {
if (res.isSuccess()) {
System.debug('Email sent successfully');
}
else {
sendResult = false;
System.debug('The following errors occurred: ' + res.getErrors());
}
}
return sendResult;
}
}
\
Now It's Showing Below Error :
Method is not visible: EmailManager.sendMail(String, String, String)
Thnaks in Advance ..
Please try changing the sendMail method signature to :
public static void sendMail(String address, String subject, String body)
If you have to invoke a method (from trigger in your case) without instantiating an object, it should be defined as Static.
If you dont want to define it as Static, please create an instance (object) for the class EmailManager and then invoke the method sentMail.
Eg:
EmailManager obj = new EmailManager();
obj.sendMail('Your email address', 'Trailhead Trigger Tutorial',
recordCount + ' contact(s) were inserted.');
Hope this helps.
Please mark it as solved if it answers your question.
Yeah Absolutely Correct ... Thansk for your quick support .
Also the class should be made static by adding "static" in the class definition, you are not instantiating an object in this trigger practice.