2

I have created a custom button to create a PDF and save it to the case Attachment. When the button is clicked, the PDF is generated and saved to the Attachments, but the issue is when the page is reloaded after the action, the Highlighted Fields Section appears twice. I've tried all the Behavior of the custom button and the isdtp param to the return page Reference, I couldn't get rid of it. Where is the mistake, any ideas on how to handle this? Thanks.

Apex Class:

public with sharing class CasePDFButtonExtension {
    ...
    public PageReference SaveAsPDF() {
        if(SavingPDFDoc == 'No') {
            return null;
        }
        PageReference PDFPAGE = new PageReference('/apex/CasePDFButtonPage');
        PDFPAGE.getParameters().put('id', cId);
        PDFPAGE.getParameters().put('SavingPDFDoc', 'No');
        Blob pdfBlob;
        pdfBlob = PDFPAGE.getContentAsPDF();

        Attachment a = new Attachment();
        a.Body = pdfBlob;
        a.ParentID = cId;
        a.Name = 'Case Attachment.pdf';
        insert a;
        return new PageReference('/' +cId); //return new PageReference('/' +cId+ '?isdtp=it');
    }
}

Visualforce Page:

<apex:page standardController="Case" extensions="CasePDFButtonExtension" 
    action="{!SaveAsPDF}" renderAs="pdf" applyHtmlTag="false" showHeader="false" sidebar="false">
...
</apex:page>

Custom Button: enter image description here Output:

enter image description here

2
  • are you in development mode? sometimes it makes pages go crazy :)
    – bananka
    Jun 9 '15 at 8:50
  • I've tried in Developer edition and sandbox. Same result in both the environments.
    – Seesh
    Jun 9 '15 at 16:45
0

I'm wondering why I was thinking too deeply. Finally, I came up with a somewhat simple solution.

I've created a new Visualforce Page for just refreshing the console in javascript. Redirected to the refresh page once the PDF attachment was inserted.

Please let me know if there is any better solution, Thanks.

New Visualforce Page - RefreshPage

<apex:page standardController="Case">
    <script> 
        window.top.location='/console';
    </script>
</apex:page>

Modified Extension

public with sharing class CasePDFButtonExtension {
    ...
    public PageReference SaveAsPDF() {
        ...
        //No change
        ...
        //Redirecting to the new visualforce page
        return new PageReference('/apex/RefreshPage' );
    }
}

Output:

enter image description here

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.