2012-04-04 3 views
1

해결 방법을 찾지 못하는 문제의 단점이 있습니다.보고서 루프에서 전달되는 Salesforce/Apex 매개 변수

클라이언트 용 PDF로 VisualForce 페이지를 만들고 있는데, 기본적으로 깔끔하게 서식이 지정된 보고서, 입력 텍스트 상자 등이 아니며 일부 데이터 즉 첨부 파일에 액세스하는 데 문제가 있습니다.

첨부 파일은 일반적으로 기회의 일부이지만, 이는 상당히 사용자 정의 된 설정이므로 데이터를 저장하는 기회 테이블에 매달려있는 두 개의 사용자 지정 개체가 있습니다. 이미지 첨부와 별도로 모든 일반 데이터를 검색했습니다.

Opportunities에는 고객이 'room'이라고 부르는 SFDC_520_Quote__c라는 사용자 지정 개체가 있으며 각 방에는 제품에 대한 링크가있는 SFDC_520_QuoteLine__c 개체가 첨부되어 있습니다.

그러나이 'room'레벨에 첨부 된 이미지에는 SFDC_520_Quote__c.id 필드의 ParentID가 주어 지므로 SFDC_520_Quote__c 사이에 정의 된 관계가 없으므로 SOQL 문을 함께 읽지 못하게됩니다 및 첨부 파일.

나는 필드를 추가 할 수 있다는 것을 알았지 만, 내가 떠난 다른 누군가로부터 데리러 오는 동안 나에게 제공되는 기존 데이터를 어떻게 업데이트 할 수 있을지 전혀 몰랐습니다.

visualforce 페이지에서 이상적으로해야 할 일은 반복 루프 동안 컨트롤러 클래스에 매개 변수를 전달하고 컨트롤러에서 작동 할 수있는 다른 getter를 호출하는 것입니다. 그러나 컨트롤러 쪽에서 변수를 설정하는 데 문제가 있습니다.

예 (주로 절단) :

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

} 

위의 잘 작동하지만 제 1 내부 후에 내가 첨부 파일을 얻을 필요가있다. 첨부 파일은 room.id를 기반으로하므로 이상적으로 visual.force에서 getter에 매개 변수를 전달할 수 없다는 점을 제외하면 'getAttachments'와 같은 일부 getter에 room.id를 전달해야합니다.

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을 수정하는 방법을 : 컨트롤러에 추가 한 후

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

그리고 :

그래서, 그것은 뭔가를 보일 수 있습니다 한 번에 관계 필드가 없기 때문에 제대로 컴파일 된 subselect를 수행하는 방법을 알아낼 수 없습니다.

나는 쿼리 문자열 매개 변수를 사용하여 이야기하는 많은 예제를 보았지만 폼이 포함되어 있지 않으며 새로 고침도없고 VF 페이지 호출도 없습니다.

도와주세요. 이미 getAllRooms 방법에 사용되는 SOQL 쿼리에서 솔루션을 가지고있는 것처럼

+0

업데이트 :이 방법을 제안하는 유일한 방법이 제안되었습니다. 티 – JamesB

답변

1

JamesB는

같습니다!

그것은 내게 당신이해야 할 모든 것
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')]; 

이 당신의 중첩 된 반복 작업 할 수 있도록해야한다 여기

은 당신이 쓴거야 두 번째 반복에 대한 사소한 조정을 통해 :

<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> 
관련 문제