Skip to content

Commit c4390d5

Browse files
authored
add reference to afterFind, add more detail on predefined classes (#653)
1 parent 0c86bc0 commit c4390d5

File tree

1 file changed

+62
-5
lines changed

1 file changed

+62
-5
lines changed

_includes/cloudcode/cloud-code.md

+62-5
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,15 @@ Parse.Cloud.beforeSave("Review", (request) => {
219219
});
220220
```
221221

222+
## Predefined Classes
223+
If you want to use `beforeSave` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself, for example:
224+
225+
```javascript
226+
Parse.Cloud.beforeSave(Parse.User, async (request) => {
227+
// code here
228+
})
229+
```
230+
222231
# afterSave Triggers
223232

224233
In some cases, you may want to perform some action, such as a push, after an object has been saved. You can do this by registering a handler with the `afterSave` method. For example, suppose you want to keep track of the number of comments on a blog post. You can do that by writing a function like this:
@@ -272,7 +281,13 @@ const afterSave = function afterSave(request) {
272281
```
273282

274283
## Predefined Classes
275-
If you want to use `afterSave` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself.
284+
If you want to use `afterSave` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself, for example:
285+
286+
```javascript
287+
Parse.Cloud.afterSave(Parse.User, async (request) => {
288+
// code here
289+
})
290+
```
276291

277292
# beforeDelete Triggers
278293

@@ -295,8 +310,14 @@ Parse.Cloud.beforeDelete("Album", (request) => {
295310
296311
If the function throws, the `Album` object will not be deleted, and the client will get an error. Otherwise,the object will be deleted normally.
297312
298-
If you want to use `beforeDelete` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself.
313+
## Predefined Classes
314+
If you want to use `beforeDelete` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself, for example:
299315
316+
```javascript
317+
Parse.Cloud.beforeDelete(Parse.User, async (request) => {
318+
// code here
319+
})
320+
```
300321
301322
# afterDelete Triggers
302323
@@ -318,15 +339,21 @@ The `afterDelete` handler can access the object that was deleted through `reques
318339
319340
The client will receive a successful response to the delete request after the handler terminates, regardless of how the `afterDelete` terminates. For instance, the client will receive a successful response even if the handler throws an exception. Any errors that occurred while running the handler can be found in the Cloud Code log.
320341
321-
If you want to use `afterDelete` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself.
342+
## Predefined Classes
343+
If you want to use `afterDelete` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself, for example:
344+
345+
```javascript
346+
Parse.Cloud.afterDelete(Parse.User, async (request) => {
347+
// code here
348+
})
349+
```
322350
323351
# beforeFind Triggers
324352
325353
*Available only on parse-server cloud code starting 2.2.20*
326354
327355
In some cases you may want to transform an incoming query, adding an additional limit or increasing the default limit, adding extra includes or restrict the results to a subset of keys. You can do so with the `beforeFind` trigger.
328356
329-
330357
## Examples
331358
332359
```javascript
@@ -384,7 +411,37 @@ Parse.Cloud.beforeFind('MyObject2', (req) => {
384411

385412
```
386413
387-
# beforeLogin Trigger
414+
## Predefined Classes
415+
If you want to use `beforeFind` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself, for example:
416+
417+
```javascript
418+
Parse.Cloud.beforeFind(Parse.User, async (request) => {
419+
// code here
420+
})
421+
```
422+
423+
# afterFind Triggers
424+
425+
*Available only on parse-server cloud code starting 2.2.25*
426+
427+
In some cases you may want to manipulate the results of a query before they are sent to the client. You can do so with the `afterFind` trigger.
428+
429+
```
430+
Parse.Cloud.afterFind('MyCustomClass', async (request) => {
431+
// code here
432+
})
433+
```
434+
435+
## Predefined Classes
436+
If you want to use `afterFind` for a predefined class in the Parse JavaScript SDK (e.g. [Parse.User]({{ site.apis.js }}classes/Parse.User.html)), you should not pass a String for the first argument. Instead, you should pass the class itself, for example:
437+
438+
```javascript
439+
Parse.Cloud.afterFind(Parse.User, async (request) => {
440+
// code here
441+
})
442+
```
443+
444+
# beforeLogin Triggers
388445
389446
*Available only on parse-server cloud code starting 3.3.0*
390447

0 commit comments

Comments
 (0)