I have 2 vf pages (one is a clone of the other one without the action)
The first one called S :
<apex:page action="{!saveAttachement}" standardcontroller="aktarus__C" extensions="Audit" applyBodyTag="false" applyHtmlTag="false" showheader="false" standardStylesheets="false">
<body>
<apex:iframe height="100%" src="/apex/s2?id={!$CurrentPage.parameters.Id}"/>
<apex:form >
{!boite1}
{!boite2}
<!-- Content -->
</apex:form>
</body>
</apex:page>
The second one called s2 :
<apex:page standardcontroller="aktarus__C" extensions="Audit" renderAs="pdf" applyBodyTag="false" applyHtmlTag="false" showheader="false" standardStylesheets="false">
<body>
<apex:form >
{!boite1}
{!boite2}
<!-- Content -->
</apex:form>
</body>
</apex:page>
And my controller:
public Audit(ApexPages.StandardController stdController) {
this.aktarus = (aktarus__c)stdController.getRecord();
accID = Apexpages.currentPage().getParameters().get('Id');
}
public void saveAttachement() {
List<Aktarus__c> listakta = [SELECT Id, Name, account__c,text1__c,Type_of_alert__c,comment__c,date__c FROM Aktarus__c ];
PageReference pdf = Page.s2;
// pdf.getParameters().put('id', Apexpages.currentPage().getParameters().get('Id'));
pdf.getParameters().put('id', accID);
boite1 =listakta[0].name;
boite2 = Apexpages.currentPage().getParameters().get('Id');
Attachment attach = new Attachment();
Blob body;
try {
// returns the output of the page as a PDF
body = pdf.getContent();
// need to pass unit test -- current bug
} catch (VisualforceException e) {
system.debug('in the catch block');
body = Blob.valueOf('Some Text');
}
attach.Body = body;
// add the user entered name
attach.Name = 'newaud.pdf';
attach.IsPrivate = false;
// attach the pdf to the account
attach.parentId = 'a0o9E000001tGQHQA2';
insert attach;
}
Where a0o9E000001tGQHQA2 is the id of one of my object.
The goal is to parse through all my custom object , do some loop to get some data, display it on my s and s2 page, and save it directly in my related attachment of my custom object. The problem is that the dynamic variable are displayed on s when I call it with a button, but they disappearon my s2 page (the one saved in my attachment) I guess the problem is coming from pdf.getparameter.put that doesn't give the good id to the s2 page but I am unable to find a solution
How can I do ?