【问题标题】:Display data from multiple objects in a Salesforce VF page in one pageblocktable在一个页面块表中显示来自 Salesforce VF 页面中多个对象的数据
【发布时间】:2016-06-23 02:11:50
【问题描述】:

我需要在 Salesforce VF 页面的单个页面块表中显示来自 2 个对象(客户和联系人)的记录,客户记录后跟联系人记录。 我知道我们可以使用包装类来实现这一点,但我遇到的所有示例都谈到了显示复选框或垂直(而不是水平)显示来自 pageblocktable 中不同对象的列。

不胜感激任何指针/代码示例。谢谢!!

        Object    Name                  Phone           Email

记录 1 - 账户 - 账户名称 - 账户电话 - 账户邮箱

记录 2 - 联系人 - 联系人名字 - 联系人电话 - 联系人电子邮件

【问题讨论】:

  • 你能更广泛地描述一下为什么你不能用包装类来满足你的需求吗?它只是一个数据容器,您可以根据需要在 UI 上对其进行处理和显示。

标签: salesforce wrapper visualforce


【解决方案1】:

我发现了一种肮脏的做法。这可能不是最佳答案,但您可以按如下方式实现所需的功能。创建一个二维数组并将不同对象的数据存储为字符串。然后遍历visualforce页面中的数组来显示数据。

public class MixedObjectVFController {

public static List<List<String>> getObjectList(){
    List<List<String>> strList = new List<List<String>>();
    List<Account> acc = [select name,phone from account limit 2];

    for(account a : acc){
        List<String> tempList = new List<String>();
        tempList.add('account');
        tempList.add(a.name);
        tempList.add(a.phone);
        strList.add(tempList);
    }
    List<contact> cList = [select name,phone from contact limit 2];
    for(contact a : cList){
        List<String> tempList = new List<String>();
        tempList.add('contact');
        tempList.add(a.name);
        tempList.add(a.phone);
        strList.add(tempList);
    }
    return strList;
} }

和 Visualforce 页面

<apex:page controller="MixedObjectVFController" >
<apex:pageBlock>
    <apex:pageBlockSection>
        <apex:pageBlockTable value="{!objectList}" var="item">
            <apex:column headerValue="Object" value="{!item[0]}" />
            <apex:column headerValue="Name" value="{!item[1]}" />
        </apex:pageBlockTable> 
    </apex:pageBlockSection>
</apex:pageBlock>

确保在使用索引时检查空值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 2021-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多