javascripttriggerscloudparse-server

Parse trigger error, afterFind expect results to be returned in the promise


I'm having an error when I try to use a simple afterFind trigger. I'm using Parse Server v4.2.0 via back4app

Parse.Cloud.afterFind('Device', async (req) => {
   console.log(req);
});

but the app crashes and start to prompt the error message

afterFind expect results to be returned in the promise

I noticed two things:

What I'm missing?


Solution

  • Because you are using async, it is expecting the promise to resolve to a query result. You have two options:

    1. since you are not using await in your trigger, you can just remove the async from your function:
    Parse.Cloud.afterFind('Device', (req) => {
       console.log(req);
    });
    
    1. You can return the objects at the end:
    Parse.Cloud.afterFind('Device', async (req) => {
       console.log(req);
       return req.objects;
    });