I’m trying to update a specific data object in backendless, and I can’t seem to get the correct syntax.
how do I join the code for updating:
Backendless.Persistence.save( contact, new AsyncCallback<Contact>() {
with the code for searching a specific data object:
String whereClause = “age = 147”;BackendlessDataQuery dataQuery = new BackendlessDataQuery();dataQuery.setWhereClause( whereClause );BackendlessCollection<Contact> result = Backendless.Persistence.of( Contact.class ).find( dataQuery );
Mark, in your code, you get all of the contacts and then perform the whereclause “age = 147” ?
I need to get all of the contacts and only then perform the search for the specific contact ?
I thought that it’s possible to retrieve only the single contact I want and then change it and save.
Backendless.Persistence.of( Contact.class).find( new AsyncCallback<BackendlessCollection<Contact>>(){ @Override public void handleResponse( BackendlessCollection<Contact> foundContacts ) { // all Contact instances have been found } @Override public void handleFault( BackendlessFault fault ) { // an error has occurred, the error code can be retrieved with fault.getCode() }});
how do I proceed in finding the specific contact I need ?
I don’t know how to “handle” the “foundContacts” list that contains all of the data.
ok, say I want to find the contact “jim” and update his last name to “kirk”.
what I think should be the code is :
String whereClause = "name = jim"; // or "name = 'jim'"
BackendlessDataQuery dataQuery = new BackendlessDataQuery();
dataQuery.setWhereClause( whereClause );
BackendlessCollection<Contacts> result = Backendless.Persistence.of(Contacts.class ).find( dataQuery );
Contacts contacts = result.getCurrentPage().get( 0 );
contacts.setlastname("kirk");
// save object asynchronously
Backendless.Persistence.save(contacts, new AsyncCallback<Contacts>() {
public void handleResponse(Contacts response) {
// new Contact instance has been saved
}
public void handleFault(BackendlessFault fault) {
// an error has occurred, the error code can be retrieved with fault.getCode()
}
});
what Android Studio thinks is that I’m an idiot and the app crashes in the line: BackendlessCollection<Contacts> result = Backendless.Persistence.of(Contacts.class ).find( dataQuery );
I’ve succeeded in retrieving the collection from Backendless:
Backendless.Data.of(Contacts.class).find(dataQuery, new AsyncCallback<BackendlessCollection<Contacts>>(){
@Override
public void handleResponse( BackendlessCollection<Contacts> foundcontacts )
{
// all Contact instances have been found
contacts = foundcontacts;
}
but how do I isolate a single Contacts row and get to the point that I can do “contacts.setName” etc ?