Skip to content

Commit f88e927

Browse files
committed
added context to object save in JS SDK
1 parent ddb5cb1 commit f88e927

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

_includes/js/objects.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,29 @@ teamMember.save(null, { cascadeSave: false });
199199

200200
```
201201

202+
### Cloud Code context
203+
204+
You may pass a `context` that is accessible in Cloud Code `beforeSave` and `afterSave` triggers for that `Parse.Object`. This is useful if you want to condition certain operations in Cloud Code triggers on ephemeral information that should not be saved with the `Parse.Object` in the database. The context is ephemeral in the sense that it vanishes after the Cloud Code triggers for that particular `Parse.Object` have executed. For example:
205+
206+
```javascript
207+
var TeamMember = Parse.Object.extend("TeamMember");
208+
var teamMember = new TeamMember();
209+
teamMember.set("team", "A");
210+
211+
var context = { notifyTeam: false };
212+
await teamMember.save(null, { context: context });
213+
```
214+
215+
The context is then accessible in Cloud Code:
216+
217+
```javascript
218+
Parse.Cloud.afterSave("TeamMember", async (req) => {
219+
var notifyTeam = req.context.notifyTeam;
220+
if (notifyTeam) {
221+
// Notify team about new member.
222+
}
223+
});
224+
```
202225

203226
## Retrieving Objects
204227

0 commit comments

Comments
 (0)