• sghosh1
  • 0 Points
  • Member since 2010

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 0


I have a Visualforcepage which is renderd as PDF and it fires of on a button click on the opportunity. When this page is generated, I create an Attachment Object and attach it to the Opportunity . The problem is every Time for a single button click, Multiple attachment objects are created and attached to the Opportunity. I am using the "action"  attribute of the page element. which I thought, is only called once when the page is first requested from the server, Then Why is it called multiple time?


here is my code for the Visualforce Page



<apex:page standardController="Opportunity" extensions="OpportunityExtension" action="{!Attach}" renderAs="PDF" >


ANd Here is my Controller code for thr Attach() function





//String id = apexpages.currentpage().getparameters().get('id');

PageReference pdf = new PageReference('/apex/Formatted_Quote?id='+apexpages.currentPage().getParameters().get('id'));



attachment = new Attachment();

count = count++;

//pdf = Page.Formatted_Quote;

blob body = pdf.getContent();

attachment.Body = body;

//attachment.IsPrivate = false;

attachment.ParentId = apexpages.currentPage().getParameters().get('id');

attachment.name = 'Quote';

attachment.Body = body;





catch(VisualforceException e){

string msg = 'Error';







return null;



  PageReference Attach()