• sghosh1
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

Hi

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

 

 

public

{

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

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

try

{

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;

Database.insert(attachment);

 

 

}

catch(VisualforceException e){

string msg = 'Error';

 

 

}

 

 

 

return null;

}

 

  PageReference Attach()