• mkdjns.123456
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 5
    Replies

What is the best way to query a three level parent child relationship? Assume you have the data model A > B > C.

 

You can't do this:

 

SELECT NAME, (SELECT Name, (SELECT Name FROM C__r) FROM B__r) FROM A

 

And you can't even do this:

 

(SELECT Name, (SELECT Name FROM C__r) FROM B__c)

 

But you can do this:

 

SELECT Name, (SELECT Name FROM B__r) FROM A__c

 

It would appear the only way to query the objects at the bottom of hte hierachy is when an entirely sepeare query. And then where do you put these? It would appear you need a seperate wrapper class to group everything together?

 

Thanks,

Jason

  • August 22, 2011
  • Like
  • 0

I'm having an issue with saving a Visualforce page as a PDF attachment.

 

My page is (simplified):

<apex:page id="thePage" standardController="Case" extensions="customStuff" renderAs="{!renderMode}" showHeader="{!renderMode != 'pdf'}" standardStylesheets="{!renderMode != 'pdf'}">

   <apex:form id="theForm" rendered="{!renderMode != 'pdf'}">
      <apex:pageBlock id="theBlock">
         <apex:pageBlockSection id="theSection" columns="3">
            <apex:pageBlockSectionItem id="theSectionItems">
               <apex:outputLabel for="chooseTemplate" value="Choose the EOB template to use:" />
                  <apex:outputPanel >
                     <apex:selectList id="chooseTemplate" value="{!template}" size="1">
                        <apex:selectOptions value="{!templates}" />
                        <apex:actionSupport event="onchange" rerender="theBlock, theLetterBody" status="loadStatus" onsubmit="javascript&colon;document.body.style.cursor = 'wait';" oncomplete="javascript&colon;document.body.style.cursor = 'default';" />
                     </apex:selectList>
                     <apex:actionStatus id="loadStatus">
                     <apex:facet name="start"><img src="/img/loading.gif" /></apex:facet>
                  </apex:actionStatus>
               </apex:outputPanel>
            </apex:pageBlockSectionItem>
            <apex:commandButton action="{!savePDF}" value="Attach PDF" rendered="{!len(template) > 1}"/>
         </apex:pageBlockSection>
      </apex:pageBlock>
   </apex:form>

      <div id="content">
      </div>
</apex:page>

 

 

And the controller (also simplified):

 

public class customStuff {

  private string caseID;
  public Case activeCase {get; set;}
  public string renderMode {get; set;}
  public string Template {get; set;}
	
  public customStuff(ApexPages.StandardController controller) {
		
    caseID = ApexPages.currentPage().getParameters().get('id');
    if (caseID != null){
      setActiveCase();
    }
    	
    	if(ApexPages.currentpage().getParameters().get('t') != null) {
    		template = ApexPages.currentpage().getParameters().get('t');
    	}
    	
    if(ApexPages.currentPage().getParameters().get('p') != null) {
      renderMode = 'pdf';
    } else {
      renderMode = null;
    }
  }

  public pageReference setActiveCase() {
    activeCase = new Case();
    this.activeCase = [select id from Case where id = :caseID];
    return null;
  }

  public pageReference savePDF() { 
    pageReference thePage = Page.customStuff;
    thePage.getParameters().put('p','pdf');
    thePage.getParameters().put('t',Template);
    thePage.getParameters().put('id',CaseID);
    
    blob body = thePage.getContent();
    
    attachment pdf = new attachment();
    pdf.filename='my filename';
    pdf.body = body;
    pdf.ParentId = activeCase.id;
    pdf.isPrivate = false;
    
  }

  public list<selectOption> getTemplates() {
    list<selectOption> theTemplates = new list<selectOption>();
    theTemplates.add(new selectOption('', '--None--'));
    theTemplates.add(new selectOption('1', 'Item 1'));
    theTemplates.add(new selectOption('2', 'Item 2'));
    theTemplates.add(new selectOption('3', 'Item 3'));
    theTemplates.add(new selectOption('4', 'Item 4'));
    return theTemplates;
  }

}

 

 

My issue is that calling the page in the savePDF method seems to ignore the added parmeters, but only in certain instances. For example, the standard header and styles are removed, but the pageBlock is still rendered. And the page doesn't render as a pdf, even though it has received a parameter instructing it to.

 

This boggles the mind, but I'm hoping there's something simple I'm missing.

 

Thanks in advance!!

 

-Mike

  • January 13, 2011
  • Like
  • 0