Salesforce/Apex参数传入报告循环
我有一个难题,我似乎找不到解决办法 我正在为一个客户做一个PDF格式的VisualForce页面,这基本上是一个格式整洁的报告,没有输入文本框等,我在访问一些数据时遇到了问题——即附件 附件通常是Opportunity的一部分,但是,这是一个相当定制的设置,因此我们有两个自定义对象挂在存储数据的Opportunity表上。我检索了除图像附件之外的所有常规数据 基本上,Opportunities有一个自定义对象SFDC_520_Quote_c,客户称之为“房间”,每个房间都有一个SFDC_520_QuoteLine_c对象的选择,这些对象连接到产品等,我可以这样做 然而,在这个“房间”级别附加的图像被赋予了SFDC_520_Quote___c.id字段的ParentID,这使得我很难获得一个SOQL语句来读取数据,因为SFDC_520_Quote___c和附件之间没有定义的关系 我意识到我可以添加一个字段,但我不知道如何在我从其他离开的人那里取回数据时在我可用的时间内更新现有数据 理想情况下,我需要在visualforce页面中做的是在重复循环期间将一个参数传递给控制器类,然后调用另一个getter,该getter可以对其进行操作,但在控制器端设置变量时遇到了问题 示例严重截断:Salesforce/Apex参数传入报告循环,salesforce,visualforce,soql,Salesforce,Visualforce,Soql,我有一个难题,我似乎找不到解决办法 我正在为一个客户做一个PDF格式的VisualForce页面,这基本上是一个格式整洁的报告,没有输入文本框等,我在访问一些数据时遇到了问题——即附件 附件通常是Opportunity的一部分,但是,这是一个相当定制的设置,因此我们有两个自定义对象挂在存储数据的Opportunity表上。我检索了除图像附件之外的所有常规数据 基本上,Opportunities有一个自定义对象SFDC_520_Quote_c,客户称之为“房间”,每个房间都有一个SFDC_520_
<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;
}
}
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;
}
上面的工作很好,但在第一次内部我需要得到附件。附件基于room.id,因此理想情况下,我需要将room.id传递给某些getter,比如“getAttachments”,除非您不能从visualforce将参数传递给getter
因此,它可能看起来像:
<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>
然后添加到控制器:
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;
}
}
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页面的调用
请帮忙。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')];
这将允许嵌套重复对第二次重复进行微调:
<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>
贾梅布
看起来您已经在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')];
这将允许嵌套重复对第二次重复进行微调:
<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>
更新:有人建议唯一的方法可能是使用apex组件更新:有人建议唯一的方法可能是使用apex组件