• Kratos55
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 5
    Replies

Hi,

 

I would like some help on sending email message. I'm relatively new to Apex and VF. Here is what I've done so far - I've created a custom button (called Mail) in a Lead page, which when clicked,  pops open a simple VisualForce form window to send an email. I have pasted below the Apex code for Email Message which I had modified based on documentation/forum:

 

 

public class SendEmailMessage {

    public String toEmail {get;set;}
    public String subject {get;set;}
    public String body {get;set;}
    
    
    private final Lead MyLead;
    public SendEmailMessage(ApexPages.StandardController controller)
    
   
    {
        this.MyLead=(Lead)controller.getRecord();
    } 
   
             
    public void sendEmail() {
        
        //create a mail object to send email 
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        String[] toaddress = (new String[]{toEmail});
        
        //email properties
        mail.setToAddresses(toaddress);
        mail.setSubject(subject);
        mail.setUseSignature(true);
        mail.setPlainTextBody(body); 
               
        // send the email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
     }   
   }

 The VF code is below:

<apex:page standardcontroller="Lead" extensions="SendEmailMessage"> 

    <apex:pageBlock title="EMAIL TEST">
        <apex:form >
        <br />
            <apex:outputLabel value="To" for="To"/>:<br/>
            <apex:inputText value="{!toEmail}" id="email"/><br/><br/>
                        
            <apex:outputLabel value="Subject" for="Subject"/>:<br />     
            <apex:inputTextarea value="{!subject}" id="Subject" cols="80" /><br/><br/>
                        
            <apex:outputLabel value="Body" for="Body"/>:<br />     
            <apex:inputTextarea value="{!body}" id="Body" rows="10" cols="80"/><br/><br/>      
            <br /><br />
                        
            <apex:commandButton value="Send Email" action="{!sendEmail}"  />
            <apex:commandButton value="Cancel" action="{!cancel}"/> 
        
        </apex:form>
    </apex:pageBlock>
</apex:page>

I'm able to send an email when I click the Send Email button on the VF page. However here is the list of issues that I've come against :

 

1. After clicking the Send Email button, I'd like to close the popped up window. I've tried using 'onclick=window.close()'. But I'm not sure if this is the correct approach.

 

2. I'd like to populate the Subject field with the Description from the Lead page when I click on the custom button (Mail) of the particular Lead.

 

Hopefully, I've explained it properly. If anybody could guide me in the right direction, I'd appreciate it.

 

Thank you.

 

 

 

 

 

 

Hi,

 

I would like some help on sending email message. I'm relatively new to Apex and VF. Here is what I've done so far - I've created a custom button (called Mail) in a Lead page, which when clicked,  pops open a simple VisualForce form window to send an email. I have pasted below the Apex code for Email Message which I had modified based on documentation/forum:

 

 

public class SendEmailMessage {

    public String toEmail {get;set;}
    public String subject {get;set;}
    public String body {get;set;}
    
    
    private final Lead MyLead;
    public SendEmailMessage(ApexPages.StandardController controller)
    
   
    {
        this.MyLead=(Lead)controller.getRecord();
    } 
   
             
    public void sendEmail() {
        
        //create a mail object to send email 
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        
        String[] toaddress = (new String[]{toEmail});
        
        //email properties
        mail.setToAddresses(toaddress);
        mail.setSubject(subject);
        mail.setUseSignature(true);
        mail.setPlainTextBody(body); 
               
        // send the email
        Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
     }   
   }

 The VF code is below:

<apex:page standardcontroller="Lead" extensions="SendEmailMessage"> 

    <apex:pageBlock title="EMAIL TEST">
        <apex:form >
        <br />
            <apex:outputLabel value="To" for="To"/>:<br/>
            <apex:inputText value="{!toEmail}" id="email"/><br/><br/>
                        
            <apex:outputLabel value="Subject" for="Subject"/>:<br />     
            <apex:inputTextarea value="{!subject}" id="Subject" cols="80" /><br/><br/>
                        
            <apex:outputLabel value="Body" for="Body"/>:<br />     
            <apex:inputTextarea value="{!body}" id="Body" rows="10" cols="80"/><br/><br/>      
            <br /><br />
                        
            <apex:commandButton value="Send Email" action="{!sendEmail}"  />
            <apex:commandButton value="Cancel" action="{!cancel}"/> 
        
        </apex:form>
    </apex:pageBlock>
</apex:page>

I'm able to send an email when I click the Send Email button on the VF page. However here is the list of issues that I've come against :

 

1. After clicking the Send Email button, I'd like to close the popped up window. I've tried using 'onclick=window.close()'. But I'm not sure if this is the correct approach.

 

2. I'd like to populate the Subject field with the Description from the Lead page when I click on the custom button (Mail) of the particular Lead.

 

Hopefully, I've explained it properly. If anybody could guide me in the right direction, I'd appreciate it.

 

Thank you.