You need to sign in to do that
Don't have an account?
kavya mareedu
}
In the above example, I need to write a trigger in such a way that whenever I create a new contact an email should be sent to me with the details also the count of number of triggers.
I have written this class for the above example:
public class EmailManager {
public static void sendMail(List<contact> contacts)
{
for(Contact c: contacts)
{
if(c.email!=null)
{
c.email='kavya@system.in';
}
}
}
}
This is the trigger:
trigger ExampleTrigger on Contact (after insert,after delete) {
list<contact> contact= Trigger.new;
if(Trigger.isInsert){
Integer recordcount= Trigger.new.size();
EmailManager.sendMail('kavya@system.in','Trailhead Trigger Tutorial', recordcount+'contact(s) were inserted.');
}else if(Trigger.isDelete){
Integer recordcount = Trigger.new.size();
}
This example is from TrialHead Module: Example
}
In the above example, I need to write a trigger in such a way that whenever I create a new contact an email should be sent to me with the details also the count of number of triggers.
I have written this class for the above example:
public class EmailManager {
public static void sendMail(List<contact> contacts)
{
for(Contact c: contacts)
{
if(c.email!=null)
{
c.email='kavya@system.in';
}
}
}
}
This is the trigger:
trigger ExampleTrigger on Contact (after insert,after delete) {
list<contact> contact= Trigger.new;
if(Trigger.isInsert){
Integer recordcount= Trigger.new.size();
EmailManager.sendMail('kavya@system.in','Trailhead Trigger Tutorial', recordcount+'contact(s) were inserted.');
}else if(Trigger.isDelete){
Integer recordcount = Trigger.new.size();
}
In trigger you are calling EmailManager class which has (String [] addresses, String [] subjects, String [] messages) as parameters but in your case you created a class which has parameters (List<Contact> contact) so in the2nd case why don't you just pass the Trigger.new . And in the class you'll write the code like :-
public class EmailManager {
public static void sendMail(List<contact> contacts)
{
Messaging.SingleEmailMessage [] emails = new Messaging.SingleEmailMessage[]{};
for(Contact c: contacts)
{
if(c.email!=null)
{
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setSubject('Trailhead Trigger Tutorial');
email.setToAddresses(new List<String> {c.email});
email.setPlainTextBody(contacts.size()+'contact(s) were inserted.);
emails.add(email);
}
}
if(emails.size()>0) {
Messaging.sendEmail(emails);
}
}
}
Hope it helps and if it does select it as the best answer. :)
I don't know what to write and how????????????? Help me!!!!!!!!!!
Trigger for the Email Manager Class which i wrote previously.
trigger ExampleTrigger on Contact (after insert,after delete) {
list<contact> contact= Trigger.new;
if(Trigger.isAfter) {
if(Trigger.isInsert || Trigger.isDelete){
EmailManager.sendMail(Trigger.new);
}
}
If the trigger is active then the trigger must be firing.
Setup > Email Administration > Deliverability
and set the Access level to All Email