+ Start a Discussion
MargiroMargiro 

Send email after form is complete.

I need to have an email sent to myself when a new order is placed. It needs to be triggered when the final save button is hit(its in a wizard). I need the "save" button to first save,then trigger the email and perform "step4" action which brings it to an alternate confirmation page. How do I create this trigger?

Heres VF page code:

<apex:page sidebar="false" standardController="lead"   showHeader="false" extensions="GLeadExtension"> 
<apex:composition template="{!$Site.Template}">
<apex:define name="body">
<h1>Conveyor Application Request Part 3/3</h1>
<apex:form >
<apex:pageBlock >


<apex:pageBlockButtons >
<apex:commandButton action="{!step4}" value="Save"/>
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>

<apex:pageBlockSection title="Installation - Additional Information" columns="2">
<apex:inputField value="{!Lead.Capacity_ton_h__c}"/>
<apex:inputField value="{!Lead.Other_intervals__c}"/>
<apex:inputField value="{!Lead.Total_conveying_distance_m__c}"/>
<apex:inputField value="{!Lead.Horizontal_m__c}"/>
<apex:inputField value="{!Lead.Vertical_m__c}"/>
<apex:inputField value="{!Lead.Number_of_bends__c}"/>
<apex:inputField value="{!Lead.Type_of_pipe_system__c}"/>
<apex:inputField value="{!Lead.Diameter__c}"/>
<apex:inputField value="{!Lead.Humidity_of_the_product__c}"/>
<apex:inputField value="{!Lead.Hygroscopic_moisture__c}"/>
<apex:inputField value="{!Lead.Product_picked_up_from__c}"/>
<apex:inputField value="{!Lead.If_Others__c}"/>
<apex:inputField value="{!Lead.The_installation_is__c}"/>
<apex:inputField value="{!Lead.The_operation_is__c}"/>
<apex:inputField value="{!Lead.Other_information__c}"/>
</apex:pageBlockSection>

</apex:pageBlock>
</apex:form>
</apex:define>
</apex:composition>
</apex:page>
Message Edited by Margiro on 04-24-2009 07:46 AM
Message Edited by Margiro on 04-24-2009 07:48 AM
aalbertaalbert

You need to use add the email functionality to the GLeadExtension action method , step4().

There is sample code for sending Outbound email with apex here.

 

 

MargiroMargiro
I'm trying this but I believe that my code for the email is in the incorrect spot because it shows up at the bottom of the page im working on. Where should the code go?
<apex:page sidebar="false" standardController="lead"   showHeader="false" extensions="GLeadExtension"> 

<apex:composition template="{!$Site.Template}">

<apex:define name="body">

<apex:form >

<h1> Conveyor Form Complete </h1>

<b1> Thank You {!Lead.firstname}. You will be contacted shortly about your order.</b1>

</apex:form>

</apex:define>

</apex:composition>



Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

String[] toAddresses = new String[] {'margiro@piab.com'};

mail.setToAddresses(toAddresses);

mail.setSenderDisplayName('Conveyor Order');

mail.setSubject('New Conveyor Order Created : ' + Lead.Id);

mail.setPlainTextBody('A new conveyor order: ' + lead.Id +' has been entered');

mail.setHtmlBody('Your case:<b> ' + case.Id +' </b> has been created'+

' View case <a> href=https://na1.salesforce.com/'+lead.Id+'>click here</a>');

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });



</apex:page>