• Michelle Tomlinson 9
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi all,

I am trying to create a Visualforce page that is a form, combining both merge fields pulled from the initiating Opportunity page and text fields to be completed by the User.  This form will then be emailed to a specific email address.  I would then set this Visualforce page as a button on the Opportunity page.  I have been able to get the Visualforce page coding to work, but cannot get the Apex code / controller to send the email.  I am not experienced in developing, so please excuse my terrible formatting and improper terminology!!

Thank you for your help!!

VISUALFORCE PAGE:
<apex:page standardController="Opportunity" extensions="SendTCSRequest">
    <apex:messages />
    <img src="https://glu26xod9g-flywheel.netdna-ssl.com/wp-content/themes/cloudtp2016/img/Cloud_Technology_Partners_Logo.svg" alt="CTP Logo" height="100" width="200"></img>
    <apex:pageblock >
            <style>
            body .bPageBlock .pbBody .red .pbSubheader{
                background-color:#c00000; font-size:150%;
            }
            body .bPageBlock .pbBody .grey .pbSubheader{
                background-color:#c0c0c0; font-size:150%;
            }
            body .bPageBlock .pbBody .grey .pbSubheader h3{
                color:#000; font-size:150%;
            }
        </style>
    <apex:outputPanel styleClass="grey" layout="block">
    <apex:pageblocksection title="Request to Engage a TCS Member on Opportunity - {!Opportunity.Name}:">
        <apex:form >
             <br /><br />
                <b>Account: </b> <apex:outputfield value=" {!Opportunity.Account.Name}"/>     
             <br /><br />
                <b>Type: </b><apex:outputfield value=" {!Opportunity.Type}"/>     
             <br /><br />
                <b>Opportunity Name: </b><apex:outputfield value="{!Opportunity.Name}"/>
             <br /><br />
                <b>Owner: </b><apex:outputfield value="{!Opportunity.Owner.Name}"/>
             <br /><br />
                <b>CTP Forecast Category: </b><apex:outputfield value="{!Opportunity.CTP_Forecast_Category__c}"/>
             <br /><br />
                <b>Stage: </b><apex:outputfield value="{!Opportunity.StageName}"/>
             <br /><br />
                <b>Amount: </b><apex:outputfield value="{!Opportunity.Amount}"/>
             <br /><br />
                <b>Close Date: </b><apex:outputfield value="{!Opportunity.CloseDate}"/>
             <br /><br />
                <b>Link: </b> <apex:outputlink value="{!LEFT($Api.Partner_Server_URL_140,FIND('.com',$Api.Partner_Server_URL_140)+4)+Opportunity.Id}" target="_blank">{!Opportunity.Name}</apex:outputlink>
             <br /><br />
        </apex:form>
    </apex:pageblocksection>
    </apex:outputPanel>
    <apex:outputPanel styleClass="red" layout="block">
    <apex:pageblocksection title="Sales Rep to fill out specifics:">
        <apex:form >    
            <br /><br />
                <b>Cloud Platform:</b><apex:outputfield value="{!Opportunity.Cloud_Platform__c}"/>
            <br /><br /> 
                <apex:outputLabel value="Industry Vertical:" for="Industry Vertical"/><br />    
                <apex:inputTextarea required="true" id="IndustryVertical" rows="1" cols="80"/>
            <br /><br /> 
                <apex:outputLabel value="Project Location:" for="Project Location:"/><br />    
                <apex:inputTextarea required="true" id="ProjectLocation" rows="1" cols="80"/>
            <br /><br /> 
                <apex:outputLabel value="Opportunity Information:" for="Opportunity Information:"/><br />    
                <apex:inputTextarea required="true" id="OpportunityInformation" rows="10" cols="80"/>
            <br /><br /> 
                <apex:outputLabel value="Has a TCS person worked with this client before?:" for="HistoricalTCS"/><br />    
                <apex:inputTextarea required="true" id="HistoricalTCS" rows="1" cols="80"/>
            <br /><br /> 
                <apex:outputLabel value="Additional Information:" for="Additional Information:"/><br />    
                <apex:inputTextarea required="true" id="AdditionalInformation" rows="10" cols="80"/>         
            <br /><br /><br />
    <apex:commandButton value="Send to TCS" action="{!send}" />
        </apex:form>
    </apex:pageblocksection>
    </apex:outputPanel>
    </apex:pageblock>
</apex:page>

APEX CONTROLLER
public class SendTCSRequest {

public Id oppId;

    public SendTCSRequest(ApexPages.StandardController controller) {
        opp = [SELECT Id, Account.Name, Type, Name, Owner.Name, CTP_Forecast_Category__c, StageName, Amount, CloseDate, Cloud_Platform__c FROM Opportunity
            WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
}

    public PageReference send() {
        return null;
    }


    public String emailTo {get; set;}
    public String emailBody {get; set;}
    public String subject {get; set;}
    public String body {get; set;}
    public String response {get; set;}
     
    private opportunity opp; 
    
    public Opportunity getOpportunity(){
    return opp;
    }   

    {
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        mail.setToAddresses(new String[] {'TCS-Engagement-Request@cloudtp.com'});
        mail.setReplyTo('bill.peldzus@cloudtp.com');
        mail.setSenderDisplayName('Owner.Name');
        mail.setSubject('Request for TCS to Engage on an Opportunity');
        mail.saveAsActivity = true;
        mail.sethtmlBody(emailBody);


        try
        {
            Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
            if(resultMail[0].isSuccess())      
                response = 'Sent!';
            else
            {
                response = resultMail[0].getErrors().get(0).getMessage();
            }
        }
        catch(System.EmailException ex)
        {
            response = ex.getMessage();
        }  

    }
    
}