我正在查看在 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;
}
它收到一条消息“标准集控制器不支持 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 的问题是它没有我需要排序的列标题值。如果有人可以帮助,请告诉我如何。