You need to sign in to do that
Don't have an account?
Jobelle Belgar 14
Create a Trigger or Class that will auto-populate "Additional to" email address field in EmailMessage object
Hi All,
I have just began practicing salesforce development and would like to ask for your help. I have a custom object Circuit__c and I create a custom button overriden by a visualforce page that leads to Send Email page with specific Email template and field values. I have to set different values on "Additional to" email field based on the value in a custom picklist or lookup field on the Circuit object. I'm not sure if I should use trigger or add some codes on my class. Here is the sample code:
Thanks for your help!
I have just began practicing salesforce development and would like to ask for your help. I have a custom object Circuit__c and I create a custom button overriden by a visualforce page that leads to Send Email page with specific Email template and field values. I have to set different values on "Additional to" email field based on the value in a custom picklist or lookup field on the Circuit object. I'm not sure if I should use trigger or add some codes on my class. Here is the sample code:
public with sharing class emailHelper { // In a separate class so that it can be used elsewhere public Circuit__c ckt {get;set;} public User myUser { get;set;} public emailHelper(ApexPages.StandardController stdController) { ckt = (Circuit__c)stdController.getRecord(); } User currentUser = [Select email from User where username = :UserInfo.getUserName() limit 1]; public PageReference sendEmail() { PageReference emailPage = new PageReference('/email/author/emailauthor.jsp'); Map<String, String> params = emailPage.getParameters(); params.put('p3_lkid',ckt.ID); //email will be attached to the activity history of the account where the button was clicked using the ckt.ID params.put('template_id','00X7F000001GKu8'); /// template ID of the email template to be shown goes here params.put('rtype','003'); params.put('p24','belgarjobelle@gmail.com; sample@dummy.org; blabla@email.com'); //currentUser.Email showing in "Additional to" field params.put('p5','support@intelletrace.com'); //email address showing in Bcc field params.put('new_template','1'); params.put('retURL',ApexPages.currentPage().getUrl()); //after send button is clicked, go back to the account where the button was clicked return emailPage; } }
Thanks for your help!
Just update your Controller with Constructor(pass ApexPages.StandardController controller )
All Answers
You can add set to address and CCtoAddress
Here are a few things to keep in mind before sending emails with Apex:
There are limits to the number of emails you can send per day.
If you can create the email alert using workflows instead of code, always do it with workflows!
It’s sometimes helpful to send emails only when a field changes to a certain value.
Sending an email with Apex is easy because you always follow the same template:
Space
Moon
Stars
When I create an email under one circuit record, I would like to pre-define the values for the "Additional to" email address field depending on the picklist value of the circuit record. If the circuit has the 'Space' value, the email address should contain "space@example.com", same goes with other values:
'Moon'=moon@example.com
'Stars'=stars@example.com
How should I do it? I have already figured out how to auto-populate the fields but I don't know how to set the criteria.
I have updated your controller and try in my vf page .It is working fine i have put here hardcoded id you have to use ckt.id there
I hope you can understand How to select diifferent address according to diff picklist.
Controller
VF page
I Hope this is helpful for you,Please select my answer as best answer.
Thanks,
Varun
It is easy
Helpful links to set temp id
1-https://th3silverlining.com/2010/05/08/using-basic-email-templates-within-apex/
2-https://techman97.wordpress.com/tag/settargetobjectid/
3-http://anuragsfdc.blogspot.in/2015/02/send-email-using-apex-and-vf-page-by.html
You can also set email temp id by name using in this way
If you need any help let me know.
Thanks,
Varun
<apex:page standardController="Custom_Object__c" extensions="MyCustomController"> </apex:page>
Just update your Controller with Constructor(pass ApexPages.StandardController controller )