Hello Account (JavaScript Remoting)

JavaScript Remoting で Hello Account。

<apex:page controller="HelloAccountRemoter">
    
<script type="text/javascript">
  function doGetAccounts() {
      HelloAccountRemoter.getAccounts(
        function(result, event) {
            for (var i = 0; i < result.length; i++) {
                console.log(result[i].Id, result[i].Name);
            }
        },
        {escape: true}
      );
  } 
</script>
    
<apex:form id="formId">
	<apex:commandButton onclick="doGetAccounts()" value="hello" rerender="formId" />
</apex:form>
    
</apex:page>

Hello Account (Ajax Toolkit)

Ajax Toolkit で Hello Account。

<apex:page >

<script src="/soap/ajax/31.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/31.0/apex.js" type="text/javascript"></script>  

<script type="text/javascript">
  function getAccounts() {
    sforce.connection.sessionId = "{!$Api.Session_ID}";
    var accounts = sforce.connection.query("SELECT Id, Name FROM Account").getArray("records");
    for (var i = 0; i < accounts.length; i++) {
      console.log(accounts[i].Id, accounts[i].Name);
    }
  }
</script>

<apex:form >
    <apex:commandButton value="hello" onclick="getAccounts();"/>
</apex:form>

</apex:page>

Hello Account (Apex and Visualforce)

Apex と Visualforce で Hello Account。

public with sharing class HelloAccountController {

  public List<Account> acctList {get; set;}

  public PageReference getAccounts() {
    acctList = [SELECT Id, Name FROM Account];
    return null;
  }
}
<apex:page controller="HelloAccountController">
    
    <apex:form >
        <apex:commandButton value="hello" action="{!getAccounts}" rerender="dtb" />
    </apex:form>
    
    <apex:dataTable var="acct" value="{!acctList}" id="dtb">
        <apex:column value="{!acct.Id}" />
		<apex:column value="{!acct.Name}" />
    </apex:dataTable>
    
</apex:page>