+ Start a Discussion

Visual force edit page to be sent in email body


 I have a visual force page with two sections each section(with input fields) showing diff object fields,from this page,i am saving/creating records of two objects at a time,when i click on save a mail should be sent with the data on the page,or the visual force page with the data in email body.

Can somebody help how to achieve this...
Thanks in Advance...
srlawr uksrlawr uk
You could write an email template that you could then send off from the "save" method in your visualforce page controller?

You must have a custom controller to handle the saving of the two objects? So in that method use some of the SimpleEmailMessage stuff to fire out an e-mail:
EmailTemplate template = [SELECT Id FROM EmailTemplate WHERE name = 'MyTemplate'];
List<Messaging.SingleEmailMessage> msgs = new List<Messaging.SingleEmailMessage>();

Messaging.SingleEmailMessage msg = new Messaging.SingleEmailMessage();
msg.setToAddress(/* work out who you want to get it */);


of course, thinking about it - I hope you have a relationship between your two objects so you can reference their two fields on the same template...

Regarding doing that, once you have setup a "Visualforce" email template - you should be able to copy and paste your page into it, jiggle the inputs into outputs and resuse that code. That is suboptimal I admit, because you'd have to maintain both files, but I don't think you can just reuse the input form as an output for e-mail.

You might be able to use "getContentAs" to attach the original Visualforce page to an e-mail as a PDF? Might that work? Turning the inputs straight into outputs (or leaving them visually as inputs, but in a PDF it would just look like a form).

Is any of that any use?