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
Mélanie TexereauMélanie Texereau 

Bug with publisher action in Salesforce

Hi,

I would create a post in Chatter with a PDF of my quote, in action for SF1. My code works fine in Salesforce 1 but in Salesforce, when I refresh my details page of my quote, a new post with my PDF is created. Each time I refreshed my page, a new post is created. Can you help me ?

This is my class :
public with sharing class VFC38_SF1_DevisPDF {

	public DevisCommande__c devis {get;set;}

	public VFC38_SF1_DevisPDF(ApexPages.StandardController sc) {
		
		devis = (DevisCommande__c) sc.getRecord();
	}

	public void redirect(){

		PageReference pageRef = new PageReference('/apex/VFP16DevisPDF?id=' + devis.Id);

		String stringToBlob = Test.isRunningTest() ? 'test' : EncodingUtil.base64Encode(pageRef.getContent());
        system.debug('### TEST 2');

        String folderId = [SELECT Id FROM Folder WHERE Name = 'Devis'].Id;
        FeedItem post = new FeedItem();

        /* Create a document */
        Document d = new Document();
        d.Name = 'Devis ' + String.valueOf(DateTime.now().format('dd/MM/yyyy hh:mm:ss'));
        d.ContentType = 'application/pdf';
        d.Type = 'pdf';
        d.FolderId = folderId;
        d.Body = EncodingUtil.base64Decode(stringToBlob);

         /* Create a post chatter */
        post.ParentId = devis.Id;
        post.Type = 'ContentPost';
        post.ContentData = d.Body;
        post.ContentFileName = d.Name+'.pdf';
    
        insert post;
	}
}

This is my VF page : 
<apex:page docType="html-5.0" sidebar="false" showheader="false" standardController="DevisCommande__c" extensions="VFC38_SF1_DevisPDF" standardStyleSheets="false" action="{!redirect}">
   
</apex:page>

Thanks for your help.

Jim JamJim Jam
Shouldn't your redirect method navigate to a different page, ie. return a PageReference? At the moment, the way you have your code, the new post will always be created whenever the page is accessed/refreshed, because you are calling the redirect method whenever the page loads.
Mélanie TexereauMélanie Texereau
Yes, I can return a Page Reference but in Salesforce 1, it isn't necessary.
So I can't call a method in my action VF page in publisher action ?

How can I do otherwise ?

Thanks for your help Jim Jam.