I've been trying to navigate to chatter file both in desktop browser and in salesforce1 from a publisher action but I can't seem to get it working.

I have a VF Page like

<script  type="text/javascript">

function redirectToFile(){
    if ( (typeof sforce != 'undefined') && (sforce != null) ) {

<apex:actionFunction name="createPDF" action="{!generatePdf}" oncomplete="redirectToFile();"/>

<script type="text/javascript">

And on the generatePdf method I insert a ContentVersion (which is happening) and return a PageReference with the Id of that 'ContentVersion`.

public ContentVersion file {get;set;}
public PageReference generatePdf(){
    file = new ContentVersion();
    //Some code to create a PDF file...
    insert file;
    return new PageReference('/' + file.Id);

When I remove the oncomplete statement the redirect works in desktop, but I haven't been able to do so in mobile.

1 Answer 1


Here is a workaround I found to get it working in both Salesforce1 and Salesforce Website:

In the page:

<apex:page standardController="Custom__c" extensions="Extension" action="{!generatePdf}">

     <script type="text/javascript">
     var fileId = '{!JSENCODE(fileId)}';
     if (fileId.length > 14) {
        if (sforce.one) {
             window.location.href = 'javascript:sforce.one.navigateToURL(\'' + fileId + '\')';

Where fileId is the ID of the generated ContentVersion (remember to just pass the ID, not the entire ContentVersion object since this will crash your view state)

In the class:

public String fileId {get; private set;}

public PageReference generatePdf(){
    ContentVersion file = new ContentVersion();
    //Some stuff to generate the pdf
    insert file;
    fileId = String.valueOf(file.Id);

    if (isS1())
        return null;
        return new PageReference('/' + fileId);

public Boolean isS1(){

    String retUrl = ApexPages.currentPage().getParameters().get('retURL');

    return String.isNotBlank(ApexPages.currentPage().getParameters().get('sfdcIFrameHost')) || String.isNotBlank(ApexPages.currentPage().getParameters().get('sfdcIFrameOrigin')) || ApexPages.currentPage().getParameters().get('isdtp') == 'p1' || (String.isNotBlank(retUrl) && retURL.contains('projectone'));



  1. The fileId.length > 14 is just to check that there is a file in context with a valid Id
  2. The method isS1() was taken from here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .