Trying to send an array of contact emails as a parameter in Cloud Code function for Parse, here is how I am doing it:
HashMap<String, ArrayList<String>> params = new HashMap<>();
ArrayList<String> array = new ArrayList<>();
array.add("contact email 1");
array.add("contact email 2");
array.add("contact email 3");
params.put("contacts", array);
ParseCloud.callFunctionInBackground("cloudFunctionName", params, new FunctionCallback<Object>() {
@Override
public void done(Object o, ParseException e) {
// do something
}
});
In the cloud function definition:contacts
should look like this:
{"contacts" : ["contact email 1", "contact email 2", "contact email 3"]}
. Each email will have some logic applied to it.
var _ = require("underscore");
Parse.Cloud.define("cloudFunctionName", function (request, response) {
var contacts = request.params.contacts;
_.each(contacts, function(contactEmail) {
var userQuery = Parse.Query(Parse.User);
userQuery.equalTo("email", contactEmail);
userQuery.first().then(
function(user) {
// there is a user with that email
},
function(error) {
// no user found with that email
});
});
The problem arises when sometimes contactEmail becomes undefined.
An error pops up saying:
Result: TypeError: Cannot call method 'equalTo' of undefined
on line where userQuery.equalTo("email", contactEmail);
is present.
Even after adding a check like
if(typeof contactEmail != "undefined") { userQuery.equalTo("email", contactEmail); }
, the error persists.
I also ensure that the email string is not empty before including it in the array.
How can this issue be resolved?