How to delete Parse Object with Cloud Code?

How to delete object in cloud code?

I’ve tried this:

xLike.destroy({useMasterKey: true}).then((xLike) => {
        // The object was deleted from the Parse Cloud.
      }, (error) => {
        // The delete failed.
        // error is a Parse.Error with an error code and message.

But this give me error.

Error: {“message”:“Cannot read property ‘destroy’ of undefined”,“code”:141} {“functionName”:“unlikePost”,“error”:{“message”:“Cannot read property ‘destroy’ of undefined”,“code”:141},“params”:{“postOwnerID”:“AQysGkzw4O”,“postID”:“U4jyUTesGT”},“user”:“AQysGkzw4O”}
error: Parse error: Cannot read property ‘destroy’ of undefined {“code”:141,“stack”:“Error: Cannot read property ‘destroy’ of undefined\n at error (/root/parse-server-example/node_modules/parse-server/lib/Routers/FunctionsRouter.js:121:16)\n at process._tickCallback (internal/process/next_tick.js:68:7)”}

It seems that your var xLike is undefined. How are you setting it?

1 Like

Omg. You are right! I was destroying a null object. I solved it now thank you

@davimacedo I want to ask one more question. When I pass post ID to cloud code I do this:
const post = new Parse.Object('Post', { id: request.params.postID });

With this I don’t have to retrieve object. My question is How to do same for a ParseUser?

const post = new Parse.Object('ParseUser', { id: request.params.userID });


const post = new Parse.Object('Parse.User', { id: request.params.userID });


const post = new Parse.Object('User', { id: request.params.userID });

You can try:

const post = new Parse.Object(Parse.User, { id: request.params.userID });


const post = new Parse.Object('_User', { id: request.params.userID });
1 Like

‘_User’ works. Parse.User didn’t work

You’re right. My bad. But I think that you can also do:

const post = new Parse.User({ id: request.params.userID });
1 Like