Skip to content

Instantly share code, notes, and snippets.

@douglascayers
Created May 2, 2017 05:46
Show Gist options
  • Select an option

  • Save douglascayers/95717267071c674ca8ea157e11039862 to your computer and use it in GitHub Desktop.

Select an option

Save douglascayers/95717267071c674ca8ea157e11039862 to your computer and use it in GitHub Desktop.
Proof of concept inspired by Matthew Hauck's question on the Success Community how to export Enhanced Note to PDF, https://success.salesforce.com/0D53A000035M8cM
/**
* Developed by Doug Ayers (douglascayers.com)
*
* Proof of concept inspired by Matthew Hauck's question
* on the Success Community how to export Enhanced Note to PDF
* https://success.salesforce.com/0D53A000035M8cM
*/
public with sharing class ContentNotePDFController {
public transient String title { get; set; }
public transient String content { get; set; }
public ContentNotePDFController( ApexPages.StandardController stdController ) {
ContentNote note = [ SELECT id, title, content FROM ContentNote WHERE id = :stdController.getId() ];
this.title = note.title;
this.content = note.content.toString();
}
}
/**
* Developed by Doug Ayers (douglascayers.com)
*
* Proof of concept inspired by Matthew Hauck's question
* on the Success Community how to export Enhanced Note to PDF
* https://success.salesforce.com/0D53A000035M8cM
*/
@isTest
private class ContentNotePDFControllerTest {
@isTest
static void test_controller() {
ContentNote cn = new ContentNote(
title = 'Test Title',
content = Blob.valueOf( 'Hello World' )
);
insert cn;
Test.startTest();
ContentNotePDFController controller = new ContentNotePDFController( new ApexPages.StandardController( cn ) );
Test.stopTest();
System.assertEquals( 'Test Title', controller.title );
System.assertEquals( 'Hello World', controller.content );
}
}
<apex:page title="{!title}" standardController="ContentNote" extensions="ContentNotePDFController" renderAs="pdf" readOnly="true" cache="false">
<h1>
<apex:outputText value="{!title}"/>
</h1>
<apex:outputText value="{!content}" escape="false"/>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment