Hello Account (Visualforce Remote Objects)

Visualforce Remote Objects で Hello Account。

<apex:page>
  <apex:remoteObjects >
    <apex:remoteObjectModel name="Account" jsShorthand="Acct" fields="Id, Name">
      <apex:remoteObjectField name="Text1__c" jsShorthand="txt"/>
    </apex:remoteObjectModel>
  </apex:remoteObjects>

  <script>
    var doGetAccounts = function() {
      new SObjectModel.Acct().retrieve({ limit: 5 }, function(err, records, event) {
        if(err) {
          console.log(err.message);
        } else {
          records.forEach(function(record) {
            console.log(record.get("Name"));
          });
        }
      });
    };
  </script>

<button onclick="doGetAccounts()">Hello Account</button>

</apex:page>

Hello Account (Ruby)

Ruby(gem:databasedotcom) で Hello Account。

$ rails console

[1] pry(main)> client = Databasedotcom::Client.new(host: "test.salesforce.com", client_secret: <client secret>, client_id: <client id>)
[2] pry(main)> client.authenticate(username: <user name>, password: <password>)
[3] pry(main)> result = client.query("SELECT Id, Name FROM Account")
[4] pry(main)> result.each do |record| ; p record ; end

Hello Account (Java without wsc)

Java で Hello Account。

$ java -classpath ./:/usr/local/axis-1_4/lib/axis-ant.jar:/usr/local/axis-1_4/lib/commons-discovery-0.2.jar:/usr/local/axis-1_4/lib/jaxrpc.jar:/usr/local/axis-1_4/lib/wsdl4j-1.5.1.jar:/usr/local/axis-1_4/lib/axis.jar:/usr/local/axis-1_4/lib/commons-logging-1.0.4.jar:/usr/local/axis-1_4/lib/log4j-1.2.8.jar:/usr/local/axis-1_4/lib/saaj.jar org.apache.axis.wsdl.WSDL2Java partner.wsdl

$ javac -classpath ./:/usr/local/axis-1_4/lib/axis-ant.jar:/usr/local/axis-1_4/lib/commons-discovery-0.2.jar:/usr/local/axis-1_4/lib/jaxrpc.jar:/usr/local/axis-1_4/lib/wsdl4j-1.5.1.jar:/usr/local/axis-1_4/lib/axis.jar:/usr/local/axis-1_4/lib/commons-logging-1.0.4.jar:/usr/local/axis-1_4/lib/log4j-1.2.8.jar:/usr/local/axis-1_4/lib/saaj.jar com/sforce/soap/partner/*.java

$ find com/ | grep "class$" | xargs jar -cvf partner.jar

$ javac -classpath ./:/usr/local/axis-1_4/lib/axis-ant.jar:/usr/local/axis-1_4/lib/commons-discovery-0.2.jar:/usr/local/axis-1_4/lib/jaxrpc.jar:/usr/local/axis-1_4/lib/wsdl4j-1.5.1.jar:/usr/local/axis-1_4/lib/axis.jar:/usr/local/axis-1_4/lib/commons-logging-1.0.4.jar:/usr/local/axis-1_4/lib/log4j-1.2.8.jar:/usr/local/axis-1_4/lib/saaj.jar HelloAccount.java

$ java -classpath ./:/usr/local/axis-1_4/lib/axis-ant.jar:/usr/local/axis-1_4/lib/commons-discovery-0.2.jar:/usr/local/axis-1_4/lib/jaxrpc.jar:/usr/local/axis-1_4/lib/wsdl4j-1.5.1.jar:/usr/local/axis-1_4/lib/axis.jar:/usr/local/axis-1_4/lib/commons-logging-1.0.4.jar:/usr/local/axis-1_4/lib/log4j-1.2.8.jar:/usr/local/axis-1_4/lib/saaj.jar HelloAccount
import com.sforce.soap.partner.LoginResult;
import com.sforce.soap.partner.QueryResult;
import com.sforce.soap.partner.SessionHeader;
import com.sforce.soap.partner.SforceServiceLocator;
import com.sforce.soap.partner.SoapBindingStub;
import com.sforce.soap.partner.sobject.SObject;

public class HelloAccount {
  public static void main(String[] args) {
    try {
      SoapBindingStub binding = (SoapBindingStub) new SforceServiceLocator().getSoap();
      LoginResult loginResult = binding.login(<user name>, <password>);
      
      SessionHeader sh = new SessionHeader();
      sh.setSessionId(loginResult.getSessionId());      
      binding._setProperty(SoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, loginResult.getServerUrl());
      binding.setHeader(new SforceServiceLocator().getServiceName().getNamespaceURI(), "SessionHeader", sh);
  
      QueryResult queryResult = binding.query("SELECT Id, Name FROM Account");
      for (SObject sobj : queryResult.getRecords()) {
        System.out.println(sobj.getId() + ", " + sobj.get_any()[1].getValue());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Hello Account (Java with WSC)

Java (WSC) で Hello Account。

$ wget https://sfdc-wsc.googlecode.com/files/wsc-23.jar
$ java -classpath wsc-23.jar com.sforce.ws.tools.wsdlc partner.wsdl partner-wsc.jar
$ javac -classpath ./:wsc-23.jar:partner-wsc.jar HelloAccount.java
$ java -classpath ./:wsc-23.jar:partner-wsc.jar HelloAccount
import com.sforce.soap.partner.*;
import com.sforce.soap.partner.sobject.SObject;
import com.sforce.ws.ConnectionException;
import com.sforce.ws.ConnectorConfig;
import java.io.FileNotFoundException;

public class HelloAccount {
  private PartnerConnection connection;
  
  private String authEndpoint = "https://test.salesforce.com/services/Soap/u/30.0";
  private String userName = <user name>;
  private String password = <password>;
  private String query = "SELECT Id, Name FROM Account";
  
  public static void main(String[] args) throws FileNotFoundException {
    HelloAccount helloAcct = new HelloAccount();
    if (helloAcct.login()) {
      helloAcct.getAccounts();
    }
  }
  
  private boolean login() throws FileNotFoundException {
    boolean success = false;
    ConnectorConfig config = new ConnectorConfig();
    config.setUsername(userName);
    config.setPassword(password);
    config.setAuthEndpoint(authEndpoint);
    config.setTraceFile("trace.log");
    config.setTraceMessage(true);
    config.setPrettyPrintXml(true);
    try {
      connection = Connector.newConnection(config);
      success = true;
    } catch (ConnectionException e) {
      e.printStackTrace();
    }
    return success;
  }
  
  private void getAccounts() {
    QueryResult queryResult;
    try {
      queryResult = connection.query(query);
      for (SObject sobj : queryResult.getRecords()) {
        System.out.println(sobj.getId() + ", " + sobj.getField("Name"));
      }
    } catch (ConnectionException e) {
      e.printStackTrace();
    }
  }
}

Hello Account (REST using cURL)

cURL で Hello Account。

$ curl -k -d grant_type=password -d client_id= -d client_secret= -d username= -d password= https://test.salesforce.com/services/oauth2/token -H 'X-PrettyPrint:1'

$ curl https://cs6.salesforce.com/services/data/v31.0/query?q=SELECT+Id+,+Name+FROM+Account -H 'Authorization: Bearer ' -H 'Content-Type: application/json' -H 'X-PrettyPrint:1'