gpt4 book ai didi

salesforce - Visualforce 中的 Apex SOQL 子查询

转载 作者:行者123 更新时间:2023-12-03 08:26:57 25 4
gpt4 key购买 nike

我正在查看在 Visualforce 页面中显示子查询 SOQL 查询。这是我的 SOQL 表达式。

public ApexPages.StandardSetController setCon {
get {
if(setCon == null) {
setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
[SELECT Contact.Id, Opportunity.Id, Contact.FirstName, Contact.LastName, Contact.Phone,Contact.Account.Name, Contact.Email,Contact.Last_Contacted__c,Contact.Membership_Type__c,Opportunity.Call_Disposition__c, Opportunity.Sales_Stage__c,Opportunity.Name, Opportunity.CloseDate, Opportunity.StageName, Opportunity.CreatedDate FROM OpportunityContactRole where Opportunity.OwnerId=:Userinfo.getUserId()]));
}
return setCon;
}
set;
}

它收到消息“StandardSetController 不支持 OpportunityContactRole”。所以我尝试从帐户中获取机会和联系信息...

所以我的 SOQL 查询更改为:

SELECT Name, (SELECT Name, Phone, Email, Last_Contacted__c, Contact.Membership_Type__c FROM Account.Contacts) , (SELECT Call_Disposition__c, StageName, CreatedDate, CloseDate FROM Account.Opportunities) FROM Account where Id=:UserInfo.getUserId()])

但现在在我的 Visualforce 页面中,我无法访问子查询字段:

<apex:page controller="SalesRepPageControllerV3" tabstyle="contact" sidebar="false" showChat="true" >
<apex:form id="theForm">
<apex:sectionHeader title="Sales Rep Page for {!$User.FirstName}"/>
<apex:pageBlock id="innerblock" mode="edit">
<apex:pageMessages />

<apex:pageBlock id="innerblock">
<apex:pageBlockSection id="pagesection">
<apex:pageBlockTable value="{!ContactOpportunity}" var="co" id="pageblocktable">
<apex:column headerValue="Created Date" value="{!co.Opportunity.CreatedDate}"/>
<apex:column headerValue="First Name" value="{!co.Contact.FirstName}"/>
<apex:column headerValue="First Name" value="{!co.Contact.LastName}"/>
<apex:column headerValue="Phone" value="{!co.Contact.Phone}"/>
<apex:column headerValue="Account Name" value="{!co.Contact.Account.Name}"/>
<apex:column headerValue="Email" value="{!co.Contact.Email}"/>
<apex:column headerValue="Last Contacted" value="{!co.Contact.Last_Contacted__c}">
</apex:column>

<apex:column headerValue="Membership Type" value="{!co.Contact.Membership_Type__c}"/>
<apex:column headerValue="Call Disposition">
<apex:inputField value="{!co.Opportunity.Call_Disposition__c}"/>
</apex:column>
<apex:column headerValue="Sales Stage">
<apex:inputField value="{!co.Opportunity.Sales_Stage__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>

</apex:pageBlock>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}" reRender="pageblocktable"/>
<apex:commandButton value="Cancel" action="{!cancel}" reRender="pageblocktable"/>
</apex:pageBlockButtons>
</apex:pageBlock>
<apex:panelGrid columns="2">
<apex:commandLink action="{!previous}">Previous</apex:commandlink>
<apex:commandLink action="{!next}">Next</apex:commandlink>
</apex:panelGrid>
</apex:form>
</apex:page>

它不理解 co.Opportunity 和 co.Contact,因为它不是帐户。如果我将它更改为 co.Opportunities 或 co.Contacts,它就是一个只能通过重复访问的 Arraylist。

apex:repeat 的问题是它没有我需要排序的列标题值。如果有人可以提供帮助,请告诉我如何做。

最佳答案

大量编辑...

我认为您不能为此使用标准集 Controller 。使用自定义 Controller ,我能够获得当前用户的机会联系人的综合列表:

enter image description here

页面:

<apex:page controller="TestQueryController">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!opportunities}" var="co">
<apex:column value="{!co.Opportunity.CreatedDate}"/>
<apex:column value="{!co.Contact.FirstName}"/>
<apex:column value="{!co.Contact.LastName}"/>
<apex:column headerValue="Stage">
<apex:inputField value="{!co.Opportunity.StageName}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</Apex:form>
</apex:page>

Controller :

public with sharing class TestQueryController {
List<OpportunityContactRole> myOCR;

public List<OpportunityContactRole> getOpportunities() {
if (myOCR == null) {
myOCR = [SELECT Contact.Id, Opportunity.Id, Contact.FirstName, Contact.LastName, Contact.Phone,
Contact.Account.Name, Contact.Email, Opportunity.Name,
Opportunity.CloseDate, Opportunity.StageName, Opportunity.CreatedDate
FROM OpportunityContactRole where Opportunity.OwnerId=:Userinfo.getUserId()];
}
return myOCR;
}
}

您需要在您的自定义字段中进行替换。如需分拣,this blog post提供了一种方法,尽管您可以使用包装类和 Apex Comparable 避免重复访问数据库。界面。最后,您需要实现自己的保存逻辑。祝你好运!

关于salesforce - Visualforce 中的 Apex SOQL 子查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11993760/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com