Héctor
Héctor

Reputation: 26034

Parse Cloud: Remove installation

I'm trying to remove an Installation that matches with a uniqueId. This is my Parse Cloud code:

Parse.Cloud.define("removeInstallation", function(req, res) {

    Parse.Cloud.useMasterKey();

    var userId = req.params.uniqueId;

    var query = new Parse.Query(Parse.Installation);
    query.equalTo("uniqueId", userId);

    query.each(function(installation) {
        installation.remove();
    });

    query.find({

        success: function(installations) {
            res.success(installations);
        },

        error: function(error) {
            res.error(error);
        }
    });
});

And I call it from my Android app like:

final String wifiMacAddress = getWifiMacAddress(context);

Map<String, String> params = new LinkedHashMap<String, String>();
params.put("uniqueId", wifiMacAddress);

ParseCloud.callFunctionInBackground("removeInstallation", params, new FunctionCallback<Object>() {
    @Override
    public void done(Object o, ParseException e) {
        if (e != null)
            throw new RuntimeException(e);
        else Log.d("Test", o);
    }
});

Cloud function call is working properly but the installation is not removed. I still can see it in Parse.com dashboard.

How can I delete it?

Upvotes: 1

Views: 182

Answers (1)

H&#233;ctor
H&#233;ctor

Reputation: 26034

Solved. I was calling remove() instead of destroy(). This is my code now:

Parse.Cloud.define("removeInstallation", function(req, res) {

    Parse.Cloud.useMasterKey();

    var userId = req.params.uniqueId;

    var query = new Parse.Query(Parse.Installation);
    query.equalTo("uniqueId", userId);

    query.find(function(installations) {
        installations[0].destroy().then(
            function() {
                res.success("Destroyed");
            },
            function() {
                res.error();
            });
    });

}); 

Upvotes: 2

Related Questions