You need to sign in to do that
Don't have an account?

Trigger help - An email from Owner to the Lead
I've written a trigger where a notification in form of an email is sent to the Owner when the Lead Status field is changed .But the requirement was different and i did it to send email to the Owner which is not.
A help in Trigger where the requirement is that, an email should be sent from the Owner to the particular Lead Please help me to achieve this..Below is the code.
Really appreciate the help.
A help in Trigger where the requirement is that, an email should be sent from the Owner to the particular Lead Please help me to achieve this..Below is the code.
Really appreciate the help.
trigger UpdateLeadStatus on Lead (after update) { Map <Id, String> leadsOwner = new Map <Id, String> (); // Go through every lead in the trigger for (Lead lead : trigger.new) { // Check if the status has been changed if (lead.Status != trigger.oldMap.get(lead.Id).Status) { // get the owner ID's that have been affected leadsOwner.put(lead.ownerId, null); } } // Map the owner ID to it's email address for (User owner : [SELECT Id, Email FROM User WHERE Id = :leadsOwner.keySet()]) { leadsOwner.put(owner.Id, owner.Email); } List <Messaging.SingleEMailMessage> emails = new List <Messaging.SingleEMailMessage> (); // Go again through every lead in the trigger for (Lead lead : trigger.new) { // Only work with leads that have owners mapped to their email addresses (only those ones have their status changed) if (leadsOwner.get(lead.OwnerId) != null) { // Create an email message and add it to the list Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); List <String> toAddresses = new List <String> {leadsOwner.get(lead.OwnerId)}; mail.setToAddresses(toAddresses); mail.setSubject('Automated Email : Lead Status Updated'); String body = 'The status has been changed on the lead record with ID ' + lead.Id; mail.setPlainTextBody(body); emails.add(mail); } } Messaging.sendEmail(emails); }
1) Make sure you organisatin has enabled sinlge messaging
2) Also instead of using mail.setToAddresses(toAddresses);try to use setTargetObjectId(lead.id); other you may hit sinlge messaging limit.
It says : Error: Compile Error: Method does not exist or incorrect signature: setTargetObjectId(Id) at line 33 column 13 . Dont know why its giving me an error while it should work.
Also how do i enable single messaging for my Org . Could you please help me.Thanks