+ Start a Discussion
ClubliClubli 

How do I automatically populate the "Additional To" field?

I want to be able to send an email from cases where the "Additional To" field is automatically populated with a custom email address we have on cases (as we do not use contacts).

 

I have been looking around for some code to do this and I have found some but I cannot get it to work for me. Can anyone see where I am going wrong? Or are you aware of another solution for this issue. The code I have been trying is:

 

Public class SendEmail
{
    public String subject {get; set;}
    public String body {get; set;}
 
    private Case cas;
   
    // Constructor to populate instance of your object
    public SendEmail(ApexPages.StandardController controller) {
    this.cas= (Case )controller.getRecord();
    cas= [SELECT cas fields required
             FROM Case
             WHERE id = :ApexPages.CurrentPage().getParameters().get('id')​];
    }
             
    public Case getCase(){
    return cas;
    }
   
   
    public pageReference send(){
    Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();  
     
    email.setSubject(subject);
    email.setToAddresses(Customer_Email_Address__c);//Use SOQL to retrieve addresses in the address
    email.setPlainTextBody(body);
    email.setBccSender(true);
   
    Messaging.SendEmailResult [] r = Messaging.SendEmail(new Messaging.SingleEmailMessage[] {email});     
    for ( Messaging.sendEmailResult result : r ) {

           if ( !r[0].isSuccess () ) {
              
               System.debug ( result  );
           }

           else{

               ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.INFO, 'Email Sent Successfully' );
               ApexPages.addMessage(msg);
           }
       }
    return null;  
}
}

VF Page

 

<apex:page StandardController="Case" extensions="SendEmail">
<apex:pageblock title="">
<apex:pageMessages ></apex:pageMessages>
<apex:form >

<apex:outputLabel value="Subject" for="Subject"/>:<br/>
<apex:inputText value="{!subject}" id="Subject" maxlength="80"/>
<br/><br/>
<apex:outputLabel value="Body" for="Body"/>:<br/>
<apex:inputTextarea value="{!body}" id="Body" rows="10" cols="80"/>
<br/><br/><br/>
<apex:commandButton value="Send Email" action="{!send}"/>
</apex:form>
</apex:pageblock>
</apex:page>



 

I also tried a URL hack but could not get it to work because I am not a developer and not fully sure of what is needed.

 

Any help would be greatly appreciated.

 

Regards,

 

Clubli

Best Answer chosen by Admin (Salesforce Developers) 
MVJMVJ

OK I have done this with a URL Hack.  You can then override the button if you want of create a new button or a URL Link.  For simplicity I have done it with a URL Link.   p24 is the text box for the "Additional To" field.

 

1.  Create a custom link at the case object.  The link should look like this: 

 

/_ui/core/email/author/EmailAuthor?rtype=003&p3_lkid={!Case.Id}&retURL=%2F{!Case.Id}&p24={!Case.<your custom filed goes here>}

 

2.  Add the link to the page layout.

 

3.  Click on the link and it navigates you to the email page.  The Additional field is populated.  It is related to the case. And it logs the activity too.

 

Good luck



 

 

All Answers

MVJMVJ

OK I have done this with a URL Hack.  You can then override the button if you want of create a new button or a URL Link.  For simplicity I have done it with a URL Link.   p24 is the text box for the "Additional To" field.

 

1.  Create a custom link at the case object.  The link should look like this: 

 

/_ui/core/email/author/EmailAuthor?rtype=003&p3_lkid={!Case.Id}&retURL=%2F{!Case.Id}&p24={!Case.<your custom filed goes here>}

 

2.  Add the link to the page layout.

 

3.  Click on the link and it navigates you to the email page.  The Additional field is populated.  It is related to the case. And it logs the activity too.

 

Good luck



 

 

This was selected as the best answer
ClubliClubli

Thanks so much!!