Problem with Users table update API

Am trying to update an existing user account with the following code
But i get this error string from the fault variable
“Could not find user by id or identity”
But the user is there in the users table and email is set as identity

String name = “Tester”;
String phone = “123”;
String email = “tester@gmail.com”;

BackendlessUser user = new BackendlessUser();
user.setProperty(“name”, name);
user.setProperty(“phone”, phone);
user.setEmail(email);

    Backendless.UserService.update(user, new AsyncCallback<BackendlessUser>() {
        public void handleResponse(BackendlessUser updatedUser) {
            
     
            Intent intent = new Intent(getApplicationContext(), MainActivity.class);
            startActivity(intent);
        }


        public void handleFault(BackendlessFault fault) {

            MaterialToast.makeText(getApplicationContext(), fault.getMessage()+email, R.drawable.ic_error_black_24dp, Toast.LENGTH_LONG).show();
            Timber.e("Update error: %s", fault.getMessage());
                            
        }

    });

Hello @Nkekere_Tommy_Minimann,

Please add the obejctId property for the object you want to update:

user.setProperty("objectId", "XXXX");

Regards,
Olha

All the other fields are supplied by the user, how do I know or how do I get the objectId field?

E.g. you can use one transaction to find user by email and then update that user.

Regards,
Olha

Seems like we are going round in a circle. Can u give me precise code sample?

Hi Nkekere,

There are two ways to update a user without knowing their objectId. One of the approaches is by using the Transations API. Using that API you create the UnitOfWork object (per the documentation) and add two operations to it. The first operation is retrieving the user by some kind of identity (such as email address). The second operation updates the user object. The result of the first operation becomes the input for the second operation. This is a more complex route, but definitely possible - you can see the examples in the documentation.

The second approach is using the “bulk update” API where you can specify the condition for updating the object (in the form of the where clause). The “bulk update” term in your case may sound misleading, since it implies that multiple objects will be updated. However, in your case, there is only one object that would match the condition. Since you know the email address of the user, the where clause to identify what object to update becomes this:

email = 'tester@gmail.com'

The API documentation for bulk update is available here:

Hope this helps.

Regards,
Mark

I’ve got it. I used the bulk update API. Thanks