How can we send PDF or MS WORD file via salesforce after inserting in it values from my user object.
Example: Sending each user (employee) a Salary certificate containing all his information
How can we send PDF or MS WORD file via salesforce after inserting in it values from my user object.
Example: Sending each user (employee) a Salary certificate containing all his information
You can attach those files as email attachment and then send to user:
// fetch attachments OR Same way you can query Document object
List<Attachment> attList = [SELECT id, Name, body, ContentType FROM Attachment WHERE Name = : employeeName];
// List of attachments handler
Messaging.EmailFileAttachment[] efaList = new Messaging.EmailFileAttachment();
for(Attachment att : attList)
{
// Create the email attachment
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName(att.Name);
efa.setBody(att.body);
efa.setContentType(att.ContentType);
efa.setInline(false);
efaList.add(efa);
}
// Attach files to email instance
email.setFileAttachments(efaList);
If you have a look here: Insert Attachment into Visualforce Email Template
You can see an example of a Visualforce email template with an attachment. I think this would personally be the best way to do it and the VF templates are pretty simple to set up :)
Hi you can create a custom visualforce page and render it as PDF. in this visualforce page you'll create PDF from your user object based on if provided in URL. Let me know if you need help with this part. If you are able to create a visualforce page that renders correct data. Rest is simple
<apex:page standardController="Account" renderAs="pdf" applyBodyTag="false">
You can store it as document before you send it to user.
PageReference Pg = Page.YouCustompage;
pg.getParameters().put('ud',userId);
Blob pdf1 = pg.getContent();
Now you can use this Blob to create a attachment set attachment.Body = pdf1; or save it wherever you want.
Please let me know if i am unclear.