-
Notifications
You must be signed in to change notification settings - Fork 41
/
favorite.ts
51 lines (40 loc) · 1.7 KB
/
favorite.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
import { flags, SfdxCommand } from '@salesforce/command';
import { singleRecordQuery } from '@mshanemc/plugin-helpers/dist/queries';
import { saveFavorite, favoriteFlagsName, favoriteFlagsStart, favoriteFlagsObject } from '../../../shared/uiApiFavorites';
import { FavoriteRequestBody } from '../../../shared/typeDefs';
export default class Favorite extends SfdxCommand {
public static description = 'query records and set the match as a favorite';
public static aliases = ['shane:data:favourite'];
public static examples = [
`sfdx shane:data:favorite -o Account -w "name='Salesforce.com'"
// finds the matching record and adds it to the end of the favorites menu
`
];
protected static flagsConfig = {
name: favoriteFlagsName,
where: flags.string({ char: 'w', required: true, description: 'SOQL where clause to match a single record' }),
object: favoriteFlagsObject,
start: favoriteFlagsStart
};
protected static requiresUsername = true;
public async run(): Promise<any> {
const conn = this.org.getConnection();
const matchedRecord = await singleRecordQuery({
conn,
query: `select id from ${this.flags.object} where ${this.flags.where}`
});
const body: FavoriteRequestBody = {
targetType: 'Record',
target: matchedRecord.Id,
name: this.flags.name ?? matchedRecord.Name ?? this.flags.object
};
if (this.flags.start) {
body.sortOrder = 1;
}
const result = await saveFavorite({ conn, body });
if (result.id.startsWith('0MV')) {
this.ux.log('Favorite Created');
}
return result;
}
}