-
-
Save swapnilshrikhande/4e99dff4bde6255ab96b04e917fa269a to your computer and use it in GitHub Desktop.
Generate PDF attachment of opprtunity details
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardController="Opportunity" extensions="Pdf_of_Attachment_Extension" renderAs="pdf"> | |
<apex:pageBlock > | |
<apex:pageBlockSection columns="1" > | |
<apex:pageBlockSectionItem >Opportunity Name: {!Opportunity.Name} </apex:pageBlockSectionItem> | |
<apex:pageBlockSectionItem >CloseDate : {!Opportunity.CloseDate} </apex:pageBlockSectionItem> | |
<apex:pageBlockSectionItem >StageName : {!Opportunity.StageName} </apex:pageBlockSectionItem> | |
<apex:pageBlockSectionItem >Probability : {!Opportunity.Probability} </apex:pageBlockSectionItem> | |
</apex:pageBlockSection> | |
<apex:repeat var="attachment" value="{!attachments}"> | |
<apex:image url="/servlet/servlet.FileDownload?file={!attachment.Id}"/><br></br> | |
</apex:repeat> | |
</apex:pageBlock> | |
</apex:page> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class Pdf_of_Attachment_Extension | |
{ | |
public String currentId {get;set;} | |
public Pdf_of_Attachment_Extension(ApexPages.StandardController controller) | |
{ | |
currentId = ApexPages.currentPage().getParameters().get('id'); | |
} | |
public List<Attachment> getattachments() | |
{ | |
List<Attachment> attachmentList = [SELECT Id, Name, Body, ContentType | |
FROM Attachment | |
WHERE Parentid =: currentId]; | |
system.debug(attachmentList); | |
return attachmentList; | |
} | |
public PageReference attachpdf(){ | |
PageReference pdf = Page.Pdf_of_Attachment; | |
pdf.getParameters().put('id',currentId); | |
Attachment attach = new Attachment(); | |
Blob body; | |
try { | |
body = pdf.getContent(); | |
} catch (VisualforceException e) { | |
system.debug('Exception :'+e); | |
} | |
attach.Body = body; | |
attach.ContentType = 'application/pdf'; | |
attach.Name = currentId +' Attachment'; | |
attach.IsPrivate = false; | |
attach.ParentId = currentId ; | |
try{ | |
insert attach; | |
} catch (DMLException e) { | |
system.debug(e); | |
} | |
PageReference pr = new pagereference('/'+currentId); | |
return pr; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardController="Opportunity" extensions="Pdf_of_Attachment_Extension" action="{!attachpdf}"> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment