I can't get this sample WSC Salesforce code to work. What am I missing? I'm trying to create a new Event for a specific Account. I don't mind querying the Account first. This seems really simple, but it's not working.
QueryResult queryResults = connection.query("SELECT Id FROM Account WHERE Name = 'TEST'");
Account account = (Account) queryResults.getRecords()[0];
Event event = new Event();
[Set required fields]
event.setAccount(account);
Event[] records = new Event[1];
records[0] = event;
SaveResult[] saveResults = connection.create(records);
The error I get is
Field name provided, Id is not an External ID or indexed field for Account
You are setting the account object as a relation to the event, this is used when you want to use an externalId to resolve which account to use. In this case you have the Id, so can set the AccountId field directly, e.g.
QueryResult queryResults = connection.query("SELECT Id FROM Account WHERE Name = 'TEST'");
Account account = (Account) queryResults.getRecords()[0];
Event event = new Event();
[Set required fields]
event.setAccountId(account.getId());
Event[] records = new Event[1];
records[0] = event;
SaveResult[] saveResults = connection.create(records);