You need to sign in to do that
Don't have an account?
Andrew Sturt
"Implementing Global Actions with Visualforce Pages" challenge
Hi, I could use some help on the "Implementing Global Actions with Visualforce Pages" challenge.
I'm okay with every step but the last one: "The page should have an input field to enter an email address and a 'Send' button that allows users to quickly email their contact information to others. Implementing this requirement is optional for passing this challenge."
I have no idea how to send the page as an email. Is there some really simple way of doing this that I'm just missing, or do I need to write an APEX class and method to accomplish this part of the challenge?
I'm okay with every step but the last one: "The page should have an input field to enter an email address and a 'Send' button that allows users to quickly email their contact information to others. Implementing this requirement is optional for passing this challenge."
I have no idea how to send the page as an email. Is there some really simple way of doing this that I'm just missing, or do I need to write an APEX class and method to accomplish this part of the challenge?
public string email { get; set; }
public void sendmail()
{
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
List<Contact> contactList= [select lastname,email from Contact Where email=:"sdfsadfasfdasdf.com"];
string [] toAddress= new string[]{};
for (Contact c:contactList){
toAddress.add (c.email);
}
email.setSubject ('Opt and Acnt');
email.setPlainTextBody ('Updt ur opt & act in SF');
email.setToAddresses (toAddress);
Messaging.sendEmail (New Messaging.SingleEmailMessage[]{email});
}
Do I put this code in a class? If so, how do I call it from the Visualforce page?
@adrew - coming to your question I thought you have to send contact details as email but you need to send entire visualforce page as Email rt ? then
public string email { get; set; }
public PageReference sendmail()
{
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
List<Contact> contactList= [select lastname,email from Contact Where email=:"sdfsadfasfdasdf.com"];
string [] toAddress= new string[]{};
for (Contact c:contactList){
toAddress.add (c.email);
}
PageReference pdf = Page.attachmentPDF;//Replace attachmentPDF with the page u have rendered as PDF
pdf.getParameters().put('id',(String)account.id);
pdf.setRedirect(true);
// Take the PDF content
Blob b = pdf.getContent();
// Create the email attachment
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('Attachement');
efa.setBody(b);
email.setSubject ('Opt and Acnt');
email.setPlainTextBody ('Updt ur opt & act in SF');
email.setToAddresses (toAddress);
email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
Messaging.sendEmail (New Messaging.SingleEmailMessage[]{email});
return null;
}
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_email_sending_attachments.htm
If my code is messy find this link
I did write a controller to send the email and used javascript remoting
Here is my visualforce markup
<apex:page docType="html-5.0" title="My Business Card" controller="sendEmail">
<script type="text/javascript" src="/canvas/sdk/js/publisher.js"></script>
<script type="text/javascript">
//When the panel is displayed, enable the submit button
Sfdc.canvas.publisher.subscribe({name: "publisher.showPanel",
onData:function(e){
Sfdc.canvas.publisher.publish(
{name: "publisher.setValidForSubmit", payload: "true"});
}});
//When the submit button is pressed, create an account, and close the panel
Sfdc.canvas.publisher.subscribe({ name: "publisher.post", onData: function(e)
{
//Create the account using the Remote Object
var body = document.getElementById("body").innerHTML;
console.log(body);
var email = document.getElementById("email").value;
console.log(email);
Visualforce.remoting.Manager.invokeAction('{!$RemoteAction.sendEmail.sendTheEmail}',
body, email,
handleResult,
{escape: true}
);
}});
function handleResult(result, event){
if(event.status) {
document.getElementById("result").innerHTML = "success";
} else {
document.getElementById("result").innerHTML = event.type +
"<br/>\n<pre>" +
event.message +
"<br/>\n<pre>" +
event.where;
}
}
</script>
<div class="bcard" id="body">
Name: {!$User.FirstName} {!$User.LastName}
Title: {!$User.Title}
Email: {!$User.Email}
Phone: {!$User.Phone}
</div>
<div class="bemail">
Enter Email: <input type="text" id="email"/>
</div>
<div id="result">
</div>
</apex:page>
here is my controller
global class sendEmail {
public sendEmail(){
}
@RemoteAction
global static PageReference sendTheEmail(String body, String emailAddress){
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[]{emailAddress};
email.setSubject('My contact info');
email.setToAddresses(toAddresses);
email.setPlainTextBody(body);
//Send the email
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
}
}