function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jgaiottojgaiotto 

PageReference getContent, Documents, Blob

Hi everyone, I am facing an issue related to Documents, Blobs, and EncodingUtils.

 

I have the following code :

 

public void print(set<Id> factureSet) {
	list<Facture__c> listFacturesToPrint = [SELECT Id
						FROM Facture__c
						WHERE Id IN : factureSet
						ORDER BY Name	];

	PageReference pageRef;
	String stringToBlob = '';
	for(Facture__c f : listFacturesToPrint) {
		pageRef = Page.VFP02Facture;
		pageRef.getParameters().put('id', f.Id);

		stringToBlob += EncodingUtil.base64Encode(pageRef.getContent());
	}

	Document d = new Document();
	d.Name = 'my text file';
	d.ContentType = 'application/pdf';
	d.Type = 'pdf';
	d.FolderId = '005b0000000ctCCAAY';
	d.Body = EncodingUtil.base64Decode(stringToBlob);

	insert d;
}

A set of Facture__c Id is passed to that function.

 

The page VFP02Facture is a Visualforce page which generates a PDF file, and takes the Facture__c object as a standard controller.

 

The purpose of the function is to create only one document which contains all the PDF files generated by VFP02Facture ; that is why I made the for loop.

 

Problem is I only got 1 PDF file in the document, the one which corresponds to the first item of the listFacturesToPrint list.

 

What do I do wrong ?

 

Thanks ;)

Arun MKArun MK

 

Hi,

 

You cannot add blob like that in apex or any language. Instead you can try to accumulate all your records in the same page and render it as PDF as you wish.

 

Regards,

Arun.

jgaiottojgaiotto
Thanks Arun_lister, but the point is that I want to let the ability to the users to generate only 1 pdf for 1 Facture__c.

As a result, my VFPage does not take a recordSetVar, but only a single record, and I do not want to have 2 almost identically pages to do almost the same thing.