Differences between revisions 1 and 2
Revision 1 as of 2013-08-01 09:26:05
Size: 1838
Comment: Added SalesforceDataContext example page
Revision 2 as of 2013-08-01 09:44:40
Size: 1839
Deletions are marked like this. Additions are marked like this.
Line 33: Line 33:
--- ----

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):

   1 UpdateableDataContext dataContext = new SalesforceDataContext("foo", "bar", "baz");
   3 Table accountTable = dataContext.getDefaultSchema().getTableByName("Account");
   5 DataSet dataSet = dataContext.query().from(accountTable).select("Id", "Name").where("BillingCity").eq("New York").execute();
   7 while (dataSet.next()) {
   8   Row row = dataSet.getRow();
   9   Object id = row.getValue(0);
  10   Object name = row.getValue(1);
  11   System.out.println("Account '" + name + "' from New York has id: " + row.getValue(0);
  12 }
  13 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.


examples/SalesforceDataContext (last edited 2013-08-01 09:44:40 by KasperSorensen)