• redfin.ax1152
  • 0 Points
  • Member since 2011

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
  • 1
I select a file, I click the button to save the file as an attachment.  This all works fine.  But if I then refresh the browser it adds that same file a second time.  If I refresh again it again adds a 3rd file and so on..

Anyone know how to fix this?  I tried nulling the attachment out in the controller but it doesnt help :(

Here is the inputfile and command button in the VF page.
<apex:pageBlockButtons location="top">
            <apex:inputFile styleClass="btn" value="{!anAttachment.Body}" fileName="{!anAttachment.Name}"/>&nbsp;
            <apex:commandButton id="saveButton" value="{!$Label.Save_Attachment}" action="{!saveAttachment}"/>

Here is the save method in the controller

// save attachment to service case
    public void saveAttachment(){
        // create bridge object for additional functionality
        Attachment__c bridge = new Attachment__c();
        bridge.External__c = false;
        bridge.Restricted__c = false;
        bridge.Service_Case__c = theCase.York_Case__c;
        insert bridge;
        // create attachment and add it to the bridge object
        anAttachment.parentId = bridge.id;
        insert anAttachment;
        anAttachment = null;
        anAttachment = new Attachment();

Here is the end result with multiple copies of the same file being attached after I clicked refresh twice.

  User-added image