Updating Data Objects android

hi ,how can update a recordset i followed this https://backendless.com/documentation/data/android/data_updating_data_objects.htm
but get a duplicate entry

what is the right api for update i dont understand

public void pagato_gennaio(final String stato,String id_utente) {

final pagamenti pg = new pagamenti();
pg.setId_utente(id_utente);
pg.setId_mese("gennaio");
pg.setStato(stato);



Backendless.Persistence.save(pg, new AsyncCallback<pagamenti>() {
    public void handleResponse(pagamenti res) {

        pg.setStato(stato);
        Backendless.Persistence.save( res, new AsyncCallback<pagamenti>() {


            @Override
            public void handleResponse( pagamenti response ) {
                // Contact instance has been updated
            }
            @Override
            public void handleFault(BackendlessFault fault )
            {
                // an error has occurred, the error code can be retrieved with fault.getCode()
            }
        } );



        

    }

    public void handleFault(BackendlessFault fault) {
        Log.i("Registration", " backendlessFault" + fault.getMessage());
       
    }
});

}

i need method just for update

Hi Capitano,

You need to set an objectId to your data object, otherwise the server won’t be able to find which object to update.

how my data object has objectId in table

Yes, but your object in code doesn’t have this same object ID (because you just created it). So there is no way to link that object in table and your object in code.

You need to do the following:

final pagamenti pg = new pagamenti();
pg.setId_utente(id_utente);
pg.setId_mese("gennaio");
pg.setStato(stato);
pg.setObjectId( <OBJECT_ID_FROM_TABLE> );

and the save it.

so i need 2 queryes first for retrive and after update

Yes, sure. If you don’t know the objectId without that (and it is likely that you don’t), then first you need to retrieve that object, update its fields, and save it.

ok Sergey Chupov thanks i found the way got it

hello Capitano, i have same issue, but i did not find any solution. plz help me.

when you do the query u must use the objectId for the object that want update

thank you sir