I'm looking for a way to open a new subtab in the service console that renders an existing form as a PDF prior to saving the form and without storing the PDF in Salesforce.

I managed to work out how to open the page in a separate window using the commandlink action and target which will open the pdf in a new browser window. My request is to open the PDF as a subtab in the service console. Using the console api the page loads so I lose the data that is entered on the form.

I know that we could have the rendered page save as document or attachment and show that as a subtab. But I would be interested to see if anyone else has had a similar request where the PDF is launched based on form data.

This visualforce markup works by opening the form in a new window:

If I use the service console api and pass in the newURL parameter an empty form displays.

  • Code that will open the PDF in a new browser window apex:commandLink value="Test Action" action="{!test}" target="_blank" styleClass="btn linkAsBtn" – Jason Cooke Aug 12 '16 at 1:26

If you really don't want to save it on the system, you can cache the form data client side using a Cookie, then access it using the Apex Cookie class. If you can use standard controller, you could use the record Id as the cookie name and it will probably be reliable. Otherwise, you might have to get creative with naming it.

Regardless, it will look something like:

public with sharing class MyExtension
    public FormData data { get; private set; }
    public MyExtension(ApexPages.StandardController controller)
        Cookie cookie = ApexPages.currentPage().getCookies().get(controller.getId());
        if (cookie != null) data = JSON.deserialize(cookie.getValue(), FormData.class);
    public class FormData
        public String input1 { get; set; }
        public String input2 { get; set; }

Then you can create a separate pdf page to consume this cookie.

<apex:page standardController="MyObject__c" extensions="MyExtension" renderAs="pdf">
    <apex:outputText value="{!data.input1}" />

The last piece of this puzzle is just serializing the form data. While perhaps not a trivial exercise, it's not exactly rocket surgery either. If you start working on it and get stuck, I'm sure you can ask more specific questions, whether here or on Stack Overflow.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.