You need to sign in to do that
Don't have an account?
Workflow email template issue - could not see object values in the body of the mail received
Hi,
Upon the deletion of my custom object(whose parent is Account), My trigger should send out an email alert.
What i have done is:
1. i have a mail template(AlertTemplate) created
Account Name:{!Account_Message__c.Account__r.Name}
Account Message: {!Account_Message__c.Name}
Created By: {!Account_Message__c.CreatedBy}
Last Modified By: {!Account_Message__c.LastModifiedBy}
2. written a trigger
EmailTemplate templateObj = [SELECT id, Name FROM EmailTemplate WHERE Name='AlertTemplate'];
Messaging.MassEmailMessage massMessage = new Messaging.MassEmailMessage();
massMessage.setTargetObjectIds(targetObjIds);
massMessage.setTemplateId(templateObj.Id);
massMessage.setSaveAsActivity(false);
massMessage.setSenderDisplayName('My Portal');
massMessage.setUseSignature(false);
massMessage.setReplyTo('no-reply@saleforce.com');
Messaging.sendEmail(new Messaging.MassEmailMessage [] { massMessage });
The Problem is: i am getting email alert, but Object values (for Account Name, Account Message, createdBy, Last ModifiedDate) are not displayed in the body of the mail.
Can any one please let me know
To access data from your custom object , you have to set the WhatId to the id of the custom object. There is a problem with Mass Email Message because the setWhatIds method does not allow us to set the whatId to the Id of a custom object. You might have to use Single Email Messaging to achieve this.
For help you can look at this : http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm.
But again with Single Email Messaging,
1. The settargetobjectId() and setWhatId() methods cant be used together if settargetobjectId() is pointing to a User Record normally.You will have to use a Visualforce Email template to avoid this issue.
2. The settargetobjectId() will take only one user at a time. If the same email is going to multiple users, you might have to add the rest of the email addresses using the setToAddresses method.
So there are concerns if you think of using this. You can look at the Email Limits here :http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
I guess single email message is way to go. You can bulkify the single email message method to send around 100 emails per sendEmail call and you can have 10 sendEmail calls in a transaction. Again if you are sending to internal user i.e. by setting tagetObjectId then emails are not counted against daily limit.
Have a look here http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound.htm