• Jobelle Belgar 14
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 6
    Replies
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:
 
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!
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:
 
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!