You need to sign in to do that
Don't have an account?
Problem with Query String Parameters Map with RenderAs="pdf"
I've spent some time trying to get some dynamic elements onto a page that is rendered as a pdf. I've isolate what I believe to be a bug and would like for someone to verify. In order to combat the various problems around losing state of member variables in page flows that contain the same controller, I've packed the url that I redirect to with query string parameters that will then be used by the target page to fill content. Like so:
String url = '/apex/PrintMultipleSOs?id=' +
ApexPages.currentPage().getParameters().get('id');
Integer counter = 0;
signaturePageItems = myServiceMap.values();
for (Service_Order__c eachSO: signaturePageItems){
if (counter == 0){
//i'm hacking this because having trouble with the map and the signature page items array
url = '/apex/PrintMultipleSOs?id=' + eachSO.id;
}
else {
url += '&so'+counter+'='+eachSO.Id;
}
counter++;
}
PageReference sigPage = new PageReference(url);
sigPage.setRedirect(true);
return sigPage;
So if I have 3 SOs, I'll end up with a query string that is {url}?id={firstRowID}&so1={secondRowID}&so2={thirdRowID}.
So now in my target page, I'll need to query for these so I want to just iterate over the map of values from
ApexPages.currentPage().getParameters(). (side note that when working in dev mode there is a query string parameter that was causing my iteration to fail until I removed it from my user profile)
//this will never work for a user that is in dev mode b/c there is an additional qs parameter for the dev mode
Map<String, String> soList = ApexPages.currentPage().getParameters();
//todo: pull the query into a list return, rather than adding to temp array and potentially hitting soql limit
for (String eachSOID:soList.values()){
tempService = [select Id,Name,Order_Stage__c, Product__c, Term__c, Product_Category__c,
Hub_Circuit_ID__c, Flex_Facility_ID__c, Ring_Name__c, Bandwidth__c,Customer_Circuit_Id__c,
Customer_PO__c, Auto_Switching__c,Card_Protection_Required__c,Core_Network_Protection_Required__c,
Colocation_Type__c, Cabinet_Rack_Provided_By__c, Primary_Power__c, Redundant_Power__c,
Address_A__c, Suite_Room_A__c, City_A__c, State_A2__c, Zip_A__c, Address_Z__c, Suite_Room_Z__c, City_Z__c, State_Z__c, Zip_Z__c,
Account__c from Service_Order__c where id = :eachSOID];
myServiceMap.put(tempService.id, tempService);
}
So this works fine when the target page is not a pdf. I'm guessing there's another hidden querystring param (like the dev mode stuff) However, brute force does appear to work on the target page. Like so:
String so1 = ApexPages.currentPage().getParameters().get('so1');
tempService = [select Id,Name,Order_Stage__c, Product__c, Term__c, Product_Category__c,
Hub_Circuit_ID__c, Flex_Facility_ID__c, Ring_Name__c, Bandwidth__c,Customer_Circuit_Id__c,
Customer_PO__c, Auto_Switching__c,Card_Protection_Required__c,Core_Network_Protection_Required__c,
Colocation_Type__c, Cabinet_Rack_Provided_By__c, Primary_Power__c, Redundant_Power__c,
Address_A__c, Suite_Room_A__c, City_A__c, State_A2__c, Zip_A__c, Address_Z__c, Suite_Room_Z__c, City_Z__c, State_Z__c, Zip_Z__c,
Account__c from Service_Order__c where id = :so1];
myServiceMap.put(tempService.id, tempService);
String so2 = ApexPages.currentPage().getParameters().get('so2');
tempService = [select Id,Name,Order_Stage__c, Product__c, Term__c, Product_Category__c,
Hub_Circuit_ID__c, Flex_Facility_ID__c, Ring_Name__c, Bandwidth__c,Customer_Circuit_Id__c,
Customer_PO__c, Auto_Switching__c,Card_Protection_Required__c,Core_Network_Protection_Required__c,
Colocation_Type__c, Cabinet_Rack_Provided_By__c, Primary_Power__c, Redundant_Power__c,
Address_A__c, Suite_Room_A__c, City_A__c, State_A2__c, Zip_A__c, Address_Z__c, Suite_Room_Z__c, City_Z__c, State_Z__c, Zip_Z__c,
Account__c from Service_Order__c where id = :so2];
myServiceMap.put(tempService.id, tempService);
Why is this misbehaving?
There are definitely differences in behavior and the request chain when using RenderAs="pdf". See here for an example, which I believe is unrelated to your problem here.
Anyway, why not use a simpler solution, which is you iterate through your map's keySet, and only retrieve the value for your query if the key begins with 'so'?
Jeremy Kraybill
Austin, TX
Looking for the keys you want with a single conditional, rather than explicitly filtering keys you don't want, is a better solution, since it protects you against SF adding other keys in the future. There are several scenarios other than dev mode where "unexpected" query params show up in the string, you really can't assume you own all the values that are passed around.
If you do want to know what params are getting added, just iterate through your keySet and print all the keys.
Jeremy Kraybill
Austin, TX
All instances will be updated over the weekend to Spring 09.
While controller state is now maintained there appears to be a new issue with passing params when rendering as a PDF:
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=9805
Thanks for the heads-up on that thread. I added a trackback b/c I'm really interested in the resolution, but...
I still have the issue with not being able to set all SelectOptions to 'checked' within a SelectCheckboxes vf component based on button click or other event. Seems like a vf gap. So, anyone have ideas about that?