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
gtuerkgtuerk 

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?

JeremyKraybillJeremyKraybill

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

gtuerkgtuerk
That's certainly where I'm headed but not stoked about it.  I want to know what additional query string parameter is tripping up my logic b/c then I'll just remove the unintended ones from the map and not have conditionals in my for loop.  really kindof the same thing, whether you iterate on the keys or the values.  thanks for the posts on controller state; that's what drove me down this query string route (instead of member arrays)
JeremyKraybillJeremyKraybill

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

TehNrdTehNrd
FYI, controller state is now maintained when rendering a PDF in Spring 09 so you probably don't need to do this.
gtuerkgtuerk
that's not going to help me in the next week, right?  I need to roll this functionality out on thursday.  Also, even if controller state is maintained, that only saves me from requerying in the target page.  I still need the user interaction bit of being able to select what is displayed on the target page so I'll still need this 'Select All' capability.
TehNrdTehNrd

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

gtuerkgtuerk

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?