I have a VisualForce page which displays some data from a standard controller, I would like to know how I can add a button which activates an apex class? I want to also pass data thats visible in the VF page to the apex class.
VF Page
<apex:page standardController="Opportunity" showHeader="false" sidebar="false">
<apex:pageBlock >
<apex:pageBlockSection title="Opportunity" columns="1">
<apex:outputField value="{!Opportunity.Name}"/>
<apex:pageBlockSectionItem >
<apex:outputText value="Contacts"/>
<apex:pageBlockTable title="Contacts"
value="{!Opportunity.Designer__r}" var="contact">
<apex:column value="{!contact.Name}"/>
<apex:column value="{!contact.Phone}"/>
</apex:pageBlockTable>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Email Apex:
Messaging.reserveSingleEmailCapacity(1);
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {'[email protected]'};
mail.setToAddresses(toAddresses);
mail.setReplyTo('[email protected]');
mail.setSenderDisplayName('John Doe');
mail.setSubject('Opportunity Request : ' + Opportunity.Id); // at the moment Opportunity ID is not linked to anything
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setPlainTextBody('Your Opportunity: ' + Opportunity.Id +' request.');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });