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
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-web-toolkit/-/75n3Th65xI0J.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment