VF Page Creation
- renderAs="pdf"
- If you need StandardController then standardController="Object" extensions="ExtensionController"
- (Or) Controller="Controller"
- showHeader="false" sidebar="false" standardStylesheets="false" applyBodyTag="false" applyHtmlTag="false"
Controller/Apex Class
- Written our logic in the Contractor to Get the VF page Params
//If using StandardController
public extensionController(ApexPages.StandardController controller) {
paramValue1= ApexPages.currentPage().getParameters().get('param1');
paramValue2= paApexPages.currentPage().getParameters().get('param2');
}
//If using custom controller
public ontroller() {
paramValue1= ApexPages.currentPage().getParameters().get('param1');
paramValue2= paApexPages.currentPage().getParameters().get('param2');
} - Written our logic in a method to Set the VF page Params
Pagereference pg ;
pg = Page.VFPAGENAME;
pg.getParameters().put('param1',value1);
pg.getParameters().put('param2',value2); - Create Content Version
ContentVersion contentVersionToInsert = new ContentVersion(
Title=yourTitle+'_'+System.now(),
PathOnClient =yourTitle+'_'+System.now()+'.pdf',
VersionData = test.isRunningTest() ?
Blob.valueof('generating for test class') :
pg.getContentaspdf(),
origin = 'H'
);
insert contentVersionToInsert ; - Create ContentDocumentLink
ContentVersion contentVersionDocument = [SELECT Id, Title, ContentDocumentId FROM ContentVersion WHERE Id = :contentVersionToInsert .Id
LIMIT 1];
ContentDocumentLink contentlinkToinsert = new ContentDocumentLink();
contentlinkToinsert .LinkedEntityId = req.contactId;
contentlinkToinsert .contentdocumentid = contentVersionDocument .contentdocumentid;
contentlinkToinsert .ShareType = 'V';
insert contentlinkToinsert ;
VF PAGE Styles: mostly used CSS
- for page bottom page number
@page {
@bottom-right {
content: "Page " counter(page) " of " counter(pages);
font-family: "Times New Roman", serif;
font-size: 13px;
}
} - page Break
page-break {
display:block;
page-break-after:always;
} - Table
table {
width:100%;
border-spacing:0;
}
td,ul,li{
font-family: "Arial Unicode MS", serif;
font-size: 11px;
}
td{
width: 260px;
height: 28px;
vertical-align: "top";
}
th {
background-color: #000000;
color:#fff;
}
Notes:
- Can't user standardStylesheets
- Can't embedded with aura/LWC in renderAs VF page
- Can't apply Lighting Styles directly
No comments:
Post a Comment