Hi, As Manoj mentioned, It is not recommended to go for development if something is possible with salesforce out of the box feature like -
- Workflow Rules
- Validation Rules
- Process Builder
- Approval Process
For your practice purpose, you can write a trigger as mentioned below -
------------Thanks,Srinivas- Please mark as solution if your problem is resolved.trigger TaskTrigger1 on Task (after insert) {
//Collecting all the Assigned to userss(Owners)
Set<Id> ownerSet = new Set<Id>();
for(Task tsk : trigger.new) {
ownerSet.add(tsk.ownerId);
}
//Query to fetch the email ids based on the owners
Map<Id,User> ownerMap = new Map<Id,User>([select id, email from User where id in: ownerSet]);
//Perparing list of email to send at a time
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
for(Task tsk : trigger.new) {
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[]{ownerMap.get(tsk.OwnerId).Email});
mail.setSubject('Task Create with Id: '+tsk.Id);
mails.add(mail);
}
//Triggering the email
Messaging.sendEmail(mails);
}
error
Close
2 answers