-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate.ts
75 lines (66 loc) · 3.38 KB
/
update.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import { flags, SfdxCommand } from '@salesforce/command';
import { singleRecordQuery } from '@mshanemc/plugin-helpers/dist/queries';
import { PushTopic } from '@mshanemc/plugin-helpers/dist/typeDefs';
export default class PushTopicUpdate extends SfdxCommand {
public static description = 'Update push topics';
public static aliases = ['shane:streaming:pushtopic:update'];
public static examples = [
`sfdx streaming:pushtopic:update -n myTopic -q "select Id,Name from account"
// modifies the push topic
`,
`sfdx streaming:pushtopic:update -n myTopic -q "select Id from account" -f All -o create,update
// modifies the push topic and sets operations and watches all fields
`
];
protected static flagsConfig = {
name: flags.string({
char: 'n',
description: 'name for the push topic',
required: true
}),
description: flags.integer({
char: 'd',
description: 'add a description to the push topic'
}),
notifyforfields: flags.string({
char: 'f',
description: 'Specifies which fields are evaluated to generate a notification',
options: ['All', 'Referenced', 'Select', 'Where']
}),
operations: flags.array({
char: 'o',
description: 'which operations should produce a notification',
options: ['create', 'update', 'delete', 'undelete']
}),
query: flags.string({
char: 'q',
description: 'The SOQL query statement that determines which record changes trigger events to be sent to the channel.'
})
};
protected static requiresUsername = true;
public async run(): Promise<any> {
const conn = this.org.getConnection();
const existing = ((await singleRecordQuery({
conn,
query: `Select Id, Query, Description, NotifyForOperationUpdate,NotifyForOperationUndelete,NotifyForOperationDelete, NotifyForOperationCreate, NotifyForFields, IsActive, ApiVersion from PushTopic where Name='${this.flags.name}'`
})) as unknown) as PushTopic;
existing.Description = this.flags.description || existing.Description;
existing.Query = this.flags.query || existing.Query;
existing.ApiVersion = this.flags.apiversion || existing.ApiVersion;
existing.NotifyForFields = this.flags.notifyforfields || existing.NotifyForFields;
existing.NotifyForOperationCreate = this.flags.operations ? this.flags.operations.includes('create') : existing.NotifyForOperationCreate;
existing.NotifyForOperationUpdate = this.flags.operations ? this.flags.operations.includes('update') : existing.NotifyForOperationUpdate;
existing.NotifyForOperationDelete = this.flags.operations ? this.flags.operations.includes('delete') : existing.NotifyForOperationDelete;
existing.NotifyForOperationUndelete = this.flags.operations
? this.flags.operations.includes('undelete')
: existing.NotifyForOperationUndelete;
await conn.sobject('PushTopic').update(existing);
// tell the user how to subscribe to it
const subscribeCommand = `sfdx streaming:subscribe -t topic -n ${this.flags.name}`;
this.ux.log(`Subscribe to your topic via ${subscribeCommand}`);
return {
object: existing,
subscribeCommand
};
}
}