• jgaiotto
  • NEWBIE
  • 55 Points
  • Member since 2013
  • Salesforce Architect
  • Bluetis


  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 9
    Replies
Hi all,

I just ran into an issue involving a static variable and a pageRef.getContent()

I have a VF Page with a custom controller that allows a user to create invoices. Then, he's got the list of invoices (more than 250 by month).
The user can check the invoices he wants, and click a button that will create a document in a Chatter Group. The document contains all the invoices in one PDF.

Since I can't pass the invoices IDs in the URL as parameteres (the max number of caracters is 4096), I use a static variable (a set<Id>).

Behind the scenes :

Let's call the controller which lists the invoices PageInvoicesController
PageInvoicesController will store in a static variable in a class (UtilClass) all the IDs of the invoices records.
Then it will call the page to build the PDF (let's say PagePDF and PagePDFController)

In its contructor, PagePDFController will seek out in the static variable the IDs, and build the PDF.
Problem : the static variable is empty.


Utils :
public class Utils {
    public static set<Id> setInvoice = new set<Id>();
    /* some other code */
}


PageInvoiceController :
public class PageInvoiceController {
    /* some other code */

  public void print(set<Id> factureSet) {
        UtilClass.setInvoice = factureSet;
        /* I tested out with UtilsClass.setInvoice.addAll(factureSet) but the same thing happened */

        PageReference pageRef = Page.PagePDF;

        String stringToBlob = Test.isRunningTest() ? 'test' : EncodingUtil.base64Encode(pageRef.getContent());
      
        /* Post insertion with EncodingUtil.base64Decode(stringToBlob); */
        /* ... */
    }
}

PagePDFController :
public class PagePDFController {
    /* some other code */
    public list<Facture__c> listFactures { get; set; }

    public PagePDFController() {
        listFactures = [SELECT Id /* and other fields */ FROM Facture__c WHERE Id IN : Utils.setInvoice];
    }
}

The Util.setInvoice is empty, so the result is an empty PDF... it looks like the constructor of PagePDFController is not called or something

What do I do wrong ? Does the pageRef.getContent() empty the static variable ? Or maybe it is not part of the scope of the static variable ?

Thank you very much for your help !

PS : "facture" is the french word for invoice. You may find it in the code above ;)

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 ;)

Hi everyone,

 

I have an inline VFPage in which I detect page closing or page refresh or whenever the user leaves the page using the <body onunload="jsFunction()">. When it happens, I call some Apex code using Javascript remote action.

 

It works perfectly in the "standard" view of a page. But when I am using the console, I can't launch the Apex remote code.

 

I made some investigation on that. Apparently, the js code is running because I can console.log() some variables, but the call of MyExtension.myMethod doesn't work.

 

The js code :

 

var var1 = 'value1';
var var2 = 'value2';

console.log(var1);
console.log(var2); MyExtension.myMethod(var1, var2, function(result, event) { if(event.status) { console.log("Update successful"); } else { console.log("Update unsuccessful"); } }, {escape:true});

cosole.log('test');

 

The Apex code :

global with sharing class MyExtension {
	@RemoteAction
	global static void myMethod(String var1, String var2) {
		// my logic
	}
}

 

Even the console.log('test') works, but the console.log('Update successful') or console.log(Update unsuccessful') does not appear... Plus, I don't get any Debug log about that remoting.

 

There is no need to see my logic because like I said it works perfectly in standard.

 

Is there any other ways to detect cosole tab or subtab closing and call some Apex logic ?

 

Thank you !

Hi everyone,

 

I would like to access to the textboxes created when a user doubleclick on a field <apex:inlineEditSupport />, is it possible thought ?

 

Thank you !

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 ;)

 

 

public  class calculator1{

public integer num1{get;set;}
public integer num2{get;set;}
public integer num3{get;set;}

 
 
public void add(){
num3=num1+num2;
//EmailConformation1 E=new EmailConformation1();
//E.sendMail();
}
}

 

hi 

i am trying to send below code as package

 

public  class calculator1{

public integer num1{get;set;}
public integer num2{get;set;}
public integer num3{get;set;}

 
 
public void add(){
num3=num1+num2;
//EmailConformation1 E=new EmailConformation1();
//E.sendMail();
}
}

 

 

but getting  error 

Class.calculator1.add: line 10, column 1 Class.MyTestClass34.test11: line 13, column 1

 

 Class.calculator1.add: line 10, column 1 Class.MyTestClass34.test11: line 13, column 1

 

 

please help me quickly

Hi everyone,

 

I have an inline VFPage in which I detect page closing or page refresh or whenever the user leaves the page using the <body onunload="jsFunction()">. When it happens, I call some Apex code using Javascript remote action.

 

It works perfectly in the "standard" view of a page. But when I am using the console, I can't launch the Apex remote code.

 

I made some investigation on that. Apparently, the js code is running because I can console.log() some variables, but the call of MyExtension.myMethod doesn't work.

 

The js code :

 

var var1 = 'value1';
var var2 = 'value2';

console.log(var1);
console.log(var2); MyExtension.myMethod(var1, var2, function(result, event) { if(event.status) { console.log("Update successful"); } else { console.log("Update unsuccessful"); } }, {escape:true});

cosole.log('test');

 

The Apex code :

global with sharing class MyExtension {
	@RemoteAction
	global static void myMethod(String var1, String var2) {
		// my logic
	}
}

 

Even the console.log('test') works, but the console.log('Update successful') or console.log(Update unsuccessful') does not appear... Plus, I don't get any Debug log about that remoting.

 

There is no need to see my logic because like I said it works perfectly in standard.

 

Is there any other ways to detect cosole tab or subtab closing and call some Apex logic ?

 

Thank you !

Hi everyone,

 

I would like to access to the textboxes created when a user doubleclick on a field <apex:inlineEditSupport />, is it possible thought ?

 

Thank you !