You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metamodel.apache.org by Apache Wiki <wi...@apache.org> on 2013/08/01 11:27:06 UTC

[Metamodel Wiki] Update of "examples/SalesforceDataContext" by KasperSorensen

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Metamodel Wiki" for change notification.

The "examples/SalesforceDataContext" page has been changed by KasperSorensen:
https://wiki.apache.org/metamodel/examples/SalesforceDataContext

Comment:
Added SalesforceDataContext example page

New page:
= Setting up MetaModel with Salesforce.com =

To connect to Salesforce.com with MetaModel you need to have:

 * A Salesforce.com username
 * The password that goes with the username
 * A security token for that user to access Salesforce.com remotely
The Salesforce.com security token can be retrieved by accessing the setup page in the upper right corner of the Salesforce layout (click [your name] -> Setup).

On the Setup page you'll find a menu item called 'Reset My Security Token'. Navigate to this menu item and have it send you the token in an email.

Let's assume your username is 'foo', your password is 'bar' and your security token is 'baz'. Here's then your Java code needed to connect to Salesforce (and a small example query):

{{{
#!java
UpdateableDataContext dataContext = new SalesforceDataContext("foo", "bar", "baz");

Table accountTable = dataContext.getDefaultSchema().getTableByName("Account");

DataSet dataSet = dataContext.query().from(accountTable).select("Id", "Name").where("BillingCity").eq("New York").execute();

while (dataSet.next()) {
  Row row = dataSet.getRow();
  Object id = row.getValue(0);
  Object name = row.getValue(1);
  System.out.println("Account '" + name + "' from New York has id: " + row.getValue(0);
}
dataSet.close();
}}}

Connecting to Salesforce.com via MetaModel allows you to treat your Salesforce data just as if it was any other database or data file. Obviously you should be aware that you access remote web services, so there's network latency involved. Therefore we encourage you to spend time figuring out proper queries etc. that will fetch all the data you need in as few roundtrips as possible. That's obviously a rule to apply to any database, but it's even a bit more relevant in the case of remote web services.

---

CategoryExamples