SOQL クエリの結果を表示する Visualforce ページを作成する例:
Apex クラス:
public with sharing class TestDisplayQueryList{
public List<Account> Records {get; set;}
public TestDisplayQueryList(){
Records =
[select Name, AccountNumber, CleanStatus from Account where CleanStatus='Pending'];
}
}
Visualforce ページ:
<apex:page controller="TestDisplayQueryList">
<apex:pageBlock title="My Content">
<apex:pageBlockTable value="{!Records}" var="Record">
<apex:column >
<apex:facet name="header">Account Name</apex:facet>
<apex:outputText value="{!Record.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Account Number</apex:facet>
<apex:outputText value="{!Record.AccountNumber}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Clean Status</apex:facet>
<apex:outputText value="{!Record.CleanStatus}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Lightning コンポーネントで SOQL クエリからのデータを表示するには、次の SOQL クエリ例を使用します。
Apex クラス accWithContController.apxc
public class accWithContController {
@AuraEnabled
public static list < Account > fetchAccount() {
// query 10 records from account with their relevant contacts and return query.
List < Account > lstOfAcc = [select Name, AnnualRevenue, BillingState, (select LastName from contacts) from Account LIMIT 10];
return lstOfAcc;
}
}
Lightning コンポーネント
<aura:component controller="accWithContController">
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="ListOfAccount" type="Account[]" description="store accounts with their child contacts"/>
<ul>
<aura:iteration items="{!v.ListOfAccount}" var="acc">
<li type="dice">AccountName : {!acc.Name}</li>
<ul>
<aura:iteration items="{!acc.Contacts}" var="con" indexVar="index">
<li>contact {!index + 1} Name : {!con.LastName}</li>
</aura:iteration>
</ul>
<hr/>
</aura:iteration>
</ul>
</aura:component>
コントローラー
({
doInit: function(component, event, helper) {
//call apex class method
var action = component.get('c.fetchAccount');
action.setCallback(this, function(response) {
//store state of response
var state = response.getState();
if (state === "SUCCESS") {
//set response value in ListOfAccount attribute on component.
component.set('v.ListOfAccount', response.getReturnValue());
}
});
$A.enqueueAction(action);
},
})000386576

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.