2012-04-04 15 views
1

解決策が見つからないような問題のヘッドスクラッチャーがあります。Salesforce/Apexパラメータがレポートループで渡されます

私はVisualforceページをクライアント用のPDFとして扱っていますが、これは基本的にはきれいに書式設定されたレポートであり、入力テキストボックスなどはなく、データにアクセスする際に問題があります。

添付ファイルは通常、機会の一部ですが、これはかなりカスタマイズされた設定なので、データを格納する機会テーブルにぶら下がっている2つのカスタムオブジェクトがあります。画像の添付ファイルとは別に、すべての通常のデータを取得しました。

基本的にOpportunitiesには、クライアントが「部屋」と呼ぶカスタムオブジェクトSFDC_520_Quote__cがあります。各部屋には、製品などへのリンクを持つSFDC_520_QuoteLine__cオブジェクトが選択されています。

しかし、この「部屋」レベルで添付された画像には、SFDC_520_Quote__c.idフィールドのParentIDが与えられているため、SFDC_520_Quote__cとの間に定義された関係がないため、SOQL文を一緒に取得することは困難ですアタッチメント。

私はフィールドを追加することができたが、私が利用可能な時間内に既存のデータを更新する方法がわからない。

Visualforceページで理想的に必要なことは、繰り返しループ中にコントローラクラスにパラメータを渡して、別のゲッタを呼び出すことですが、コントローラ側で変数を設定する際に問題があります。

例(重く切り捨て):

<apex:page renderAs="pdf" standardController="Opportunity" extensions="myController"> 
    <apex:repeat value="{!allRooms}" var="room"> 
    <h1>{!room.Name}</h1> 
    <apex:repeat value="{!room.QuoteLines__r}" var="ql"> 
     <p>{!ql.Product2__r.Name}: {!ql.Product2__r.Description} - {!ql.Description__c}</p> 
    </apex:repeat> 
    </apex:repeat> 
</apex:page> 

マイコントローラ:

public class myController { 
    public List<SFDC_520_Quote__c> getAllRooms() { 
    List<SFDC_520_Quote__c> roomWithQuoteList = [select id, Name, Quote_Amount__c, Quote__c, 
     (select Item_Order__c, Product2__r.ProductCode, Product2__r.Name, Product2__r.Description, Description__c from QuoteLines__r order by Item_Order__c) 
     from SFDC_520_Quote__c where Opportunity__c =: ApexPages.currentPage().getParameters().get('id')]; 

    return roomWithQuoteList;  
    } 

} 

上記正常に動作しますが、第一の内側の後、私は添付ファイルを取得する必要があります。添付ファイルはroom.idに基づいているため、room.idをgetAttachmentsのようなゲッターに渡す必要があります。ただし、Visualforceからゲッターにパラメータを渡すことはできません。

だから、それは次のようになります。

<apex:page renderAs="pdf" standardController="Opportunity" extensions="myController"> 
    <apex:repeat value="{!allRooms}" var="room"> 
    --> something to call a setter with value from {!room.id} <-- 
    <h1>{!room.Name}</h1> 
    <apex:repeat value="{!room.QuoteLines__r}" var="ql"> 
     <p>{!ql.Product2__r.Name}: {!ql.Product2__r.Description} - {!ql.Description__c}</p> 
    </apex:repeat> 
    <apex:repeat value="{!allAttachments}" var="attachment"> 
     <apex:image height="200px" value="{!URLFOR($Action.Attachment.Download, attachment.Id)}"/> 
    </apex:repeat> 
    </apex:repeat> 
</apex:page> 

をそして、コントローラへの追加:

private String oppParentID; 

public void setParentID(string theID) { 
    oppParentID = theID; 
} 

public List<Attachment> getAllAttachments() { 
    List<Attachment> theAttachments = [select Id, Name, ContentType, .... from Attachment where parentiD =: oppParentID]; 
    return theAttachments; 
} 

こと、または上記を行うには私の元getAllRooms()メソッドを変更する方法一度に、関係フィールドはなく、適切にコンパイルされた場所で副選択を行う方法を理解することはできません。

私は、クエリ文字列パラメータを使用しているが、フォームは関係なく、リフレッシュされず、VFページを呼び出すだけであるという多くの例を見てきました。

助けてください。

+0

更新:これを行うには唯一の方法が推奨されていますt – JamesB

答えて

1

JamesB、

あなたはすでにあなたのgetAllRooms方法で使用するSOQLクエリで解決策を持っているように見えます!ここで

は、あなたが書いたものだ:

List<SFDC_520_Quote__c> roomWithQuoteList = [select id, Name, Quote_Amount__c, Quote__c, 
     (select Item_Order__c, Product2__r.ProductCode, Product2__r.Name, Product2__r.Description, Description__c from QuoteLines__r order by Item_Order__c) 
     from SFDC_520_Quote__c where Opportunity__c =: ApexPages.currentPage().getParameters().get('id')]; 

あなたがしなければならないすべては、SOQLクエリに余分な要素を追加している私には思える:

List<SFDC_520_Quote__c> roomWithQuoteList = [select id, Name, Quote_Amount__c, Quote__c, 
     (select Item_Order__c, Product2__r.ProductCode, Product2__r.Name, Product2__r.Description, Description__c from QuoteLines__r order by Item_Order__c), 
     (select Id, Name, ContentType from Attachments) 
     from SFDC_520_Quote__c where Opportunity__c =: ApexPages.currentPage().getParameters().get('id')]; 

これはあなたのネストされた繰り返しが動作できるようにする必要があります2回目のリピートにマイナーチェンジして:

<apex:page renderAs="pdf" standardController="Opportunity" extensions="myController"> 
    <apex:repeat value="{!allRooms}" var="room"> 
    <h1>{!room.Name}</h1> 
    <apex:repeat value="{!room.QuoteLines__r}" var="ql"> 
     <p>{!ql.Product2__r.Name}: {!ql.Product2__r.Description} - {!ql.Description__c}</p> 
    </apex:repeat> 
    <apex:repeat value="{!room.Attachments}" var="attachment"> 
     <apex:image height="200px" value="{!URLFOR($Action.Attachment.Download, attachment.Id)}"/> 
    </apex:repeat> 
    </apex:repeat> 
</apex:page> 
関連する問題