0

I've got an afterSave handler in Cloud Code that conditionally calls a custom method.

From my testing, both functions appear to be working exactly as desired. The custom method is skipped appropriately (with confirming console messages looking correct). It is also called appropriately, and the custom method creates a new object exactly as desired.

What's confusing me is that when the custom method IS called, I get something like the following in my Cloud Code log:

Input: {"title":"title","ownerId":"ownerId"}
Result: undefined

Like I said, the values seem to be passed in correctly, and the method seems to run correctly, but I don't understand why I get Result: undefined.

In the method that is called, I've placed a response.success() or response.error() in every pathway that's possible.

So, is this something to worry about?

The custom method is a "fire-and-forget" type of method, so my afterSave method doesn't wait around for a response. Is that why I'm getting Result: undefined?

1 Answer 1

4

The reason you are getting undefined is because your response and error functions don't pass any values. Replace it with this.

success: function(result) {
    //...
    response.success(result);
},
error: function(error) {
    response.error(error);
}

Then you'll no longer have an undefined result.

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

3 Comments

Alternatively, if you really don't want to return anything, but still don't want the response to be "undefined", you can do response.success({});
Ah, ok. I was doing response.error(error), but just response.success(). That's great to know! So, just a response.success('success') seems like a good solution, then, right?
Yup, that would work! You can respond with anything you'd like.

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.