Backendless Support
 
Waiting for user's response

To retrieve the fields of a record in V4 ....

Hi,

Continuing my step

from V3 to V4 ...

Can you give me an

example of how to retrieve the records of a table using the Map received when

making a query?.

For example, if my

"Persons" record has the fields int numPerson, String Name and String Address, as I

get them in (1):

Backendless.Data.of( "Persons" ).find( queryBuilder,

new AsyncCallback<List<Map>>(){

@Override

public void handleResponse( List<Map> foundContacts )

{

// every loaded object from the "Persons" table is now an individual java.util.Map

(1) ... ?

}

@Override

public void handleFault( BackendlessFault fault )

{

// an error has occurred, the error code can be retrieved with fault.getCode()

}

});

Thanks,

Leave a Comment

Comments (3)

photo
1

The code you provided is fine, you can retrieve the fields from a Map using Map.get("fieldName") method.

You can also use Persons class, if you have such.

Please refer to the docs, it has lots of examples both with Map and with your custom class: https://backendless.com/docs/android/doc.html#data_basic_search

photo
1

These examples do not help me and the only thing I do is waste a lot of time trying to apply something that is very different from what was already implemented in 3.0 and that works perfectly.

Please, I need complete examples of how to perform:

- A search of a record by retrieving the fields of a table on a MAP and how to retrieve from this MAP each field (which can be of different attributes STRING, INT, Geopoint ...).

- An update of this records (which I must first select).

- A deletion of this record (which I must first select).

I do not know how to convert the treatment of a BackendlessCollection to a Map.

I can provide you from my App with the examples you need to get the equivalent. I only need one for each (search, update and deletion).

Many thanks in advance, I love BackEndLess and apologize for my ignorance in this migration theme ...

photo
1

When you retrieving data from the database in version 4 you get a Java collection (List to be presize) of objects. The objects you get are either instances of java.util.HashMap (if you use the dictionary approach) or instances of your class (when you use the class-based approach). Both approaches are documented.

In your code where you use BackendlessCollection, you can replace it with List.

When you het a collection of HashMap objects, the callback from the API will deliver to your code List<HashMap>, where every HashMap represents an object from the database. To get values for specific columns, you use the "get" method on HashMap.

If you use the class-based approach, the callback returns to your code List<YourClass>. In this case, you use fields/properties declared in your class to get specific values.

To update an object, you make a change in either HashMap instance or in YourClass instance and then use the "save" method to save it back in the database.

Hope this helps.

Mark