function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jason Cooke 2Jason Cooke 2 

RenderAs PDF in Service Console - open as a Subtab

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:
<apex:commandLink value="Test Action" action="{!test}" target="_blank" styleClass="btn linkAsBtn"></apex:commandLink>

If I use the service console api and pass in the newURL parameter an empty form displays.  So I'm looking for a solution where I can invoke the commandlink action and have the target set to a new subtab instead of _blank
Jason Cooke 2Jason Cooke 2
This is a test page that I built to see what options are available:
<apex:page standardcontroller="Account" extensions="JC1a" deferLastCommandUntilReady="true">
    <apex:includescript value="/soap/ajax/30.0/connection.js" />
<apex:includescript value="/support/console/34.0/integration.js" />
<apex:includescript value="{!$Resource.CSA_CustomJQueryResource}" />
<apex:includescript value="{!$Resource.ConsoleAPI}" />

    <apex:form id="form1">
<apex:outputPanel >
        <script type="text/javascript">
    function test1() {
window.open('{!sURL}', '_blank');
        }
    function consoleOpen() {
        strTabURL = '{!sURL}';
        strWindow = '_blank';
        buttonNewWindow();
        }
    </script>        
        </apex:outputPanel>

        <apex:inputText value="{!sTest}"/> <!-- This is a test to see if I can show this on the PDF page -->
<apex:commandLink value="Opens in New Window" action="{!test}" target="_blank" styleClass="btn linkAsBtn"></apex:commandLink>
<apex:commandLink value="Button Fails" rerender="form1" oncomplete="consoleOpen();" styleClass="btn linkAsBtn" action="{!test2}"></apex:commandLink>
    </apex:form>
</apex:page>

The controller is here:
public class JC1a {
    public JC1a(ApexPages.StandardController controller) {
        
    }
    public static string sTest {get; set; }
    public PageReference test() {
        PageReference pg = new PageReference('/apex/JC1aa');
        return pg;
    }
    public string sURL { get; set; }
    public PageReference test2() {
        PageReference pg = new PageReference('/apex/JC1aa');
        sURL = pg.getUrl();
        return null;
    }
}

The 2nd page which renders as a PDF is here:
<apex:page standardcontroller="Account" extensions="JC1a" renderAs="pdf" deferLastCommandUntilReady="true"> <apex:form > <apex:outputText value="Result: {!sTest}"/> </apex:form> </apex:page>
Jason Cooke 2Jason Cooke 2
So for the 2 buttons above the first button "Opens in New Window" will open the PDF document in a new window, which is ok, but I want it to open in the service console.  The 2nd button is using the service console api (we have a cut down version of the code from: https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_opensubtab.htm

The tab will open fine, it just isnt displaying the text