user3820044
user3820044

Reputation: 177

Updating existing record in parse.com not working it doing duplication

I am working on parse.com demo, I want to update an existing entry from a table in parse.com. Each time it makes a duplicate entry. I have tried what's below.

ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("MQOD");

        // query.orderByDescending("createdAt");
        query.whereEqualTo("DeviceId", android_id);

        // query.toString();
        System.out.println("::::::::::::::::::QUERY:::::::::::::::"
                + query);
        try {
            ob = query.find();
        } catch (com.parse.ParseException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
        testObject.put("DeviceId", android_id);
        testObject.put("InstallationDate", subscriptionDate);
        testObject.put("Subscription", "Done");
        testObject.put("NextSubscription", upGradeDate);

        try {
            testObject.save();
        } catch (com.parse.ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else {
        // Purchase error...!!
        System.out.println("::::::::::::::::::::::::Purchase consumehas failed:::::::::::::::::::::");
    }
}

Upvotes: 1

Views: 358

Answers (1)

Luca Iaco
Luca Iaco

Reputation: 3467

From your code seems that you don't use the standard field id objectID( that is the official id field used in all the Parse class table ) but the DeviceId ( i suppose it is your custom field ) .

Otherwise you have to make your DeviceId as unique field, and to make it possible, you have to check the new incoming DeviceId in the "beforeSave" parse trigger, and so check if the element already exist or not ( see also this: https://www.parse.com/questions/unique-fields--2 )

So, at now it's normal that you obtain a dubplicate each time, because it is considered as Insert instead of Update ( since you don't specify the objectId )

Hope it helps

Upvotes: 2

Related Questions