1

I'm developing a kind of message application which is work on parse.com. My users and user's messages are on parse database. I want to delete one of user's all messages from parse, but i couldn't do it. I used a few methods for it like this but it doesn't works.

ParseObject msgObject;
public void DeleteAllUserMessage(String sender){

            ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Messages");
            query.whereEqualTo("personSender",sender);
             msgObj.createWithoutData("Messages", sender).deleteEventually(new DeleteCallback() {

                @Override
                public void done(ParseException e) {
                    // TODO Auto-generated method stub
                    try {
                        msgObj.delete();
                    } catch (ParseException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                    }
                }
            });

2 Answers 2

1

Supposing that personSender field is being well used you can do the following to delete all messages sent by an user:

String sender = "-> This is the user that sent the messages <-";

ParseQuery<ParseObject> query = ParseQuery.getQuery("Messages");
query.whereEqualTo("personSender", sender);
query.findInBackground(new FindCallback<ParseObject>() {
    public void done(List<ParseObject> messages, ParseException e) {
        if (e == null) {
            // remove all messages at once
            try {
               ParseObject.delete(messages);
            }catch(ParseException pe) { pe.printStackTrace(); }

            // OR (do not use both!)

            // iterate over all messages and delete them
            for(ParseObject message : messages)
            {
                 message.deleteEventually();
            }
        } else {
            Log.d("Semothing went wrong. Show useful message based on ParseException data", e.getMessage());
        }
    }
});
Sign up to request clarification or add additional context in comments.

4 Comments

com.parse.ParseException: object not found for delete exception, but in my Messages class there is 10 message for "john" user
print sender variable to the console and see if it is correct. Also make sure your user is logged in.
I solved problem, there is a user permission ACL was false. i added defaultACL.setPublicWriteAccess(true); it works fine. Thanks bro
you're welcome... Without that permission you could only delete messages related to the current logged in user.
1
reject.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            //for rejecting and deleting the request
            Log.i("MSG", "On click Reject");
            ParseObject.createWithoutData("Request", oId).deleteEventually();
            Log.i("MSG", "Successfully deleted the request");

        }
    });

Where Request is Class Name and oId is object Id, and make sure you have set the condition

ParseACL.setPublicWriteAccess(true);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.