What I'm trying to accomplish is when I call this cloud function (deploy), it will first delete all data from toClass, then iterate over objects in fromClass, copy and save them to toClass. When it saves an object, it will also delete it from fromClass. Simply put, move the objects from class to another. Calling this function on client
[PFCloud callFunctionInBackground:@"deploy" withParameters:@{@"toClass": kTilrClassUpdates, @"fromClass": kTilrClassPrototypeUpdates} block:^(id object, NSError *error) {
if (error) {
[self failed];
} else {
[self succeeded];
}
}];
Will print this error message to client log: Error: undefined (Code: 141, Version: 1.2.19)
Here is the code for Parse Cloud:
Parse.Cloud.define("deploy", function(request, response) {
var query = new Parse.Query(request.params.toClass);
query.find({
success: function(results) {
for (var i = 0; i < results.length; ++i) {
console.log(results[i]);
results[i].destroy({
success: function(object) {
},
error: function(object, error) {
response.error(error);
}
});
}
},
error: function() {
response.error(error);
}
});
var query2 = new Parse.Query(request.params.fromClass);
query2.find({
success: function(results) {
for (var index = 0; index < results.length; ++index) {
var UpdateInfoClass = Parse.Object.extend(request.params.toClass);
var updateInfo = new UpdateInfoClass();
for (var k in results[index]) {
updateInfo.set(k, results[index][k]);
}
console.log(updateInfo);
updateInfo.save(null, {
success: function(updateInfo) {
results[index].destroy();
if (index == results.length - 1) {
response.success();
}
},
error: function(updateInfo, error) {
response.error(error);
}
});
}
},
error: function() {
response.error(error);
}
});
});
I really don't know much about JavaScript, so this could be a very simple mistake somewhere.