APEX类列出要在VisualForce页面中使用的多个查询
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了APEX类列出要在VisualForce页面中使用的多个查询相关的知识,希望对你有一定的参考价值。
* SF发展的新手*我正朝着这个目标努力;在商机上创建自定义按钮。按下该按钮时,VisualForce页面将显示与该机会(ID)有关系的2个自定义对象的记录。两个自定义对象都通过自定义查找字段与“商机”相关联。
作为一名新秀,我不确定我是不是在正确的位置开始。这就是我想要的想法。以下代码适用于下面的第1和第2项。
- 创建一个查询单独数据的类方法。每种方法都是一个单独的查询/列表
- 包括编码以提取当前机会ID的变量
- 创建显示查询数据的VisualForce页面
- 创建触发APEX代码的按钮
public with sharing class TestDisplayQueryList{
public Opportunity currRec {get; set;}
public static List<Opportunity> oppRecords {get; set;}
public static List<Billing__c> billRecords {get; set;}
public static List<Service__c> servRecords {get; set;}
public TestDisplayQueryList(){
currRec = [SELECT ID FROM Opportunity WHERE :ApexPages.currentPage().getParameters().get('id')];
oppRecords = [SELECT Name, StageName ID FROM Opportunity WHERE ID= :currRec];
billRecords = [SELECT Name, Invoice ID FROM Billing WHERE Opportunity_Name_c= :currRec];
servRecords = [SELECT Name, Department ID FROM Service WHERE Opportunity_Name_c= :currRec];
}
}
3.)有很多方法可以做到这一点,最简单的只是一个页面块表https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_quick_start_iteration_components.htm
将您的值作为您的控制器列表,您将需要一个单独的页面表列表。
4.)创建自定义按钮或链接,您可以使用salesforce自定义按钮执行此操作,只需将其设为网址并将其传递给网址末尾的?id。这将自动导致代码运行,因为代码可以在页面初始化时运行。您将此按钮放在商机页面上。
如果你想在一个弹出窗口中显示信息(对于系统看起来更好看),你也可以做一个自定义按钮,只需做一个javascript按钮。有大量的在线教程,可以在javascript中为弹出窗口制作按钮。 javascript可以扩展到控制器并传递机会ID。
如果你遇到困难,请告诉我,祝你好运!
说实话,你可以比你想象的更容易。
VisualForce拥有大量标准组件,可用于此类任务。
下面是一个示例VisualForce页面:
<apex:page standardController="Opportunity" extensions="OpportunityExt">
<!-- Either include all related lists by setting the relatedList attribute to true -->
<apex:detail subject="{!opportunity.Id}" relatedList="false"/>
<!-- Or by Including the related lists seperately -->
<apex:relatedList list="OpportunityLineItems" />
<apex:relatedList list="OpportunityCompetitors" />
<!-- To use a button to display a panel, create the panel to reRender after our button action is complete -->
<apex:outputPanel id="thePanel">
<!-- Then create the buttons -->
<apex:commandButton action="{!showThePanel}" value="Show Panel" reRender="thePanel" rendered="{!NOT(showPanel)}"/>
<apex:commandButton action="{!hideThePanel}" value="Hide Panel" reRender="thePanel" rendered="{!showPanel}"/>
<!-- And inside that panel create a block that will only render when the flag is set -->
<!-- Note the use of outputPanel and outputText differently -->
<!-- OutputText leaves no container behind, outputPanel does so we need it for the "identifying panel" -->
<apex:outputText rendered="{!showPanel}">
<!-- You can then include the related lists you wanted -->
<apex:relatedList list="OpenActivities" />
</apex:outputText>
</apex:ouputPanel>
</apex:page>
这将是该页面的扩展:
public with sharing class OpportunityExt {
private Opportunity theOpportunity;
public Boolean showPanel {get; private set;}
public OpportunityExt(ApexPages.StandardController controller) {
// Get the Opportunity from the standard controller
theOpportunity = (Opportunity) controller.getRecord();
// By default don't display the panel - or do, it's your task
showPanel = false;
}
public void showThePanel() {
showPanel = true;
}
public void hideThePanel() {
showPanel = false;
}
}
这里有文档链接供您参考:
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_page.htm https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_detail.htm https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_relatedList.htm https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_commandButton.htm https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_outputPanel.htm https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_outputText.htm
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_extension.htm
以上是关于APEX类列出要在VisualForce页面中使用的多个查询的主要内容,如果未能解决你的问题,请参考以下文章
Salesforce学习之路-developer篇利用Visualforce Page实现页面的动态刷新案例学习
Visualforce页面根据案例类别显示案例计数,单击每个类别我想获得案例的详细视图。怎么样?