Using the Force.com App Engine connector to pass data to the client side

20 views
Skip to first unread message

Drew Spencer

unread,
Jan 27, 2012, 8:55:45 AM1/27/12
to google-we...@googlegroups.com
Hey coders,


I managed to get it working, and it pulls in a list of my salesforce.com accounts and writes them to the page. However, for someone using GWT as well as GAE, this is not much good. 

Is there a way to pass a DTO of some kind to the client, as if it was a regular RPC call getting data from the datastore? If anyone has any experience with this I would appreciate any input. Sorry, but I am still trying to fully understand servlets :/

Cheers,

Drew

Drew Spencer

unread,
Feb 3, 2012, 7:43:06 AM2/3/12
to google-we...@googlegroups.com
Just thought I'd post an update here as I solved this problem The problem was not at all that I couldn't pass data to the client side. You can indeed create a regular RPC Service which makes calls to the Force.com api instead of the datastore, then pass this data to the client as a list or whatever you like.

My mistake was not putting my security token after the password while trying to login. Doh!

Here is the code that is in my ServiceImpl class:

       public List<Account> getStuff()
{
List<Account> list = new ArrayList<Account>();
try
{
// config
ConnectorConfig config = new ConnectorConfig();
config.setTransport(GaeHttpTransport.class);
config.setUsername("usernamehere");
config.setPassword("pasword+TOKEN");

config.setTraceMessage(true);
// initialise connection
PartnerConnection connection = Connector.newConnection(config);
// give it a query
QueryResult qr = connection.query("SELECT Id, Name FROM Account ORDER BY Name ASC");
// put records in array
SObject[] records = qr.getRecords();
// add to list as Account
for(int i = 0; i < qr.getSize() ; i++)
{
String id = records[i].getId();
String name = (String) records[i].getField("Name");
Account account = new Account(id, name);
list.add(account);
}
return list;
}
catch(ConnectionException e)
{
System.out.print(e.getMessage());
System.out.print(e.getStackTrace());
//System.out.print(e.getMessage());
return null; // empty
}
}

It converts the SObjects to Account objects and returns them in a list, as I prefer this to returning an array or SObjects.

Drew
Reply all
Reply to author
Forward
0 new messages