1

Scenario is when new users add or signup an object of that user must be created in 'userPrivileges' class with some default values,

I am using below code for that

Parse.Cloud.beforeSave(Parse.User, function(request, response)
{
  if(request.object.isNew())
  {
    var userPrivilege = Parse.Object.extend("userPrivileges");
    var userPriv = new userPrivilege();
    userPriv.set("userType","Normal");
    userPriv.set("userID",request.object.id);
    userPriv.set("submitQus",true);
    userPriv.save();
    response.success();
  }
  else
  {
    response.success();
  }
});

The issue is object added to userPrivileges but doest not get User's objectId which I am assigning to 'userPrivileges' userID.. where I am wrong?

1 Answer 1

3

It is not possible to get objectID in beforeSave hook if the object isNew() because the object is not in the database yet, ergo doesn't have an id. You should use afterSave hook and existed() instead.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you I should have think that :D
You gave me vote up but not marked the answer as accepted meta.stackexchange.com/questions/5234/… thanks in advance

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.