I was able to get it working by changing the save call in the service class to the synchronous model. With the async version Realm complained about accessing realm objects from a different thread. That fix led to another discovery - Backendless didn’t like empty collection of postalAddressRelation. I made a change where empty collections for new entity objects are not sent to the server IF there is an uninitialized objectId property. So to get this working you need to do 3 things:
Grab the latest jar from the github repo
Change the save call in the service class to be synchronous (remove AsyncCallback)
Add objectId getter/setter into the Profiles class.
Please let me know how it goes.
Hi Mark,
When i update any record at that time instead of updating it will create new record in backendless.
Is there any need of setting objectId using getter setter method?
when you call Backendless.Data.of( YOURCLASS ).save( YOUROBJECT ), the method will return an updated object, which will contain assigned objectId. So the code should look like this:
Actually what i want is when i save data from realm to Backendless it work fine but i want thai if i have 5 profile object from realm and from service i find object which are updated in realm so suppose i found 3 object from 5 is updated and try to save that in backendless it will not update already existing object but rather create a new object.
This is the code which i do in Service and this code will create new record rather than updating…
Realm profileRealm = Realm.getInstance(Helper.getProfileConfig(getApplicationContext()));
RealmResults<Profiles> resultsProfile = profileRealm.where(Profiles.class).findAll();
final List<Profiles> profilelist = new ArrayList<>();
for (Profiles profile : resultsProfile) {
try {
Date date1 = formatter.parse(Helper.getProfileLastUpdateTime(getApplicationContext())); // last sync date
String str2 = profile.getUpdatedDate();
Date date2 = formatter.parse(str2);
if (date1.compareTo(date2) < 0) {
profilelist.add(profile);
}
} catch (Exception e) {
}for (int i = 0; i < profilelist.size(); i++) {
Backendless.Data.of(Profiles.class).save(profile);
}}