A service that queries the Resource (Contact) object using filters for security controls, region/practice/group, skills, utilization, and others. Queries can be set to return resources that do not exactly match the filter criteria (fuzzy matching). When fuzzy matching is enabled, depending on a specified preference resources may be returned that do not match the region, practice, and group filters. Certain additionalContactFilters can also be set to fuzzy match when fuzzy matching is enabled. (Currently the only additionalContactFilter that can be set to be fuzzy is resource role.) The level of preference for these filters can be defined by weightings in the Resource Search Service custom settings. The priority of weightings is Essential (must match), Ideal, Desirable, then Suggested. When using fuzzy matching the returned resources are ordered so that the best matching resources occur first. This order supersedes any requested order specified by the filter's orderByFields. A good match is determined firstly by how well the filter criteria match, then by the overall skill ratings, and finally the availability.
global static List<Contact> execute(pse.ResourceSearchService.ResourceSearchFilter filter)
The execute method searches for resources that meet the supplied criteria. Note if the search criteria use encrypted fields, the results cannot be sorted or filtered and an error displays.
An instance of the ResourceSearchService.ResourceSearchFilter class that supplies the search criteria.
Return Value
Returns a list of Contact records with the requested fields and skills, and optionally additional utilization related fields.
Sample Code
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
//Note: This sample code is for demonstration purposes only. It is not intended for
//use in a production environment, is not guaranteed against defects or errors, and
//is in no way optimized or streamlined.
/*
Declare an instance of the class used to define the resource search API execute method criteria.
*/
pse.ResourceSearchService.ResourceSearchFilter rsf = new pse.ResourceSearchService.ResourceSearchFilter();
/*
******************************************
******** Security Related Options ********
******************************************
*/
/*
The disableSharingModel option enables bypassing the sharing model on objects involved in the API Call. For example, Contact, Assignments, Resource Requests, Utilization Engines, Skills, Skill Ratings, and others.
Set to true to run the API "without sharing" and retrieve records even if the sharing model restricts the record visibility for the user.
Set to false for the API to respect the sharing model.
*/
rsf.disableSharingModel = true;
/*
The disableSecurityOnReturnedData option bypasses the CRUD/FLS on objects that are involved in the query for objects or fields that are returned in the results. For example, Contact, Assignments, Resource Requests, Utilization Engines, Skills, Skill Ratings, and others.
Set to true to run the API to skip enforcement of CRUD/FLS permission, and retrieve data even if the permissions restrict the record visible for the user.
Set to false for the API to respect CRUD/FLS permissions.
*/
rsf.disableSecurityOnReturnedData = true;
/*
The disableSecurityOnSearchCriteria option bypasses the CRUD/FLS on objects involved in the query for objects or fields used to filter the results. For example, Contact, Assignments, Resource Requests, Utilization Engines, Skills, Skill Ratings, and others.
Set to to true causes the API to skip enforcement of CRUD/FLS permission and retrieve data even if the permissions restrict the record visible for the user.
Set to false for the API to respect CRUD/FLS permissions.
*/
rsf.disableSecurityOnSearchCriteria = true;
/*
The applyStaffingPermissionControls option restricts the search to resources for which the user has staffing rights based on the PSA permission controls.
Set to true to restrict search results to resources that the user can create assignments for, based on PSA permission controls.
Set to false for the API to ignore staffing permission controls.
For more information on staffing rights, see PSA Permission Controls in the PSA Online Help. If you are developing a UI to create resource assignments,
*/
rsf.applyStaffingPermissionControls = false;
/*
*****************************************
******** Results Related Options ********
*****************************************
/*
/*
Use the fieldsToSelect parameter to specify which fields on Contact to return.
*/
Set<String> flds = new Set<String>{'FirstName','LastName','Fax','Email','pse__Is_Resource__c','pse__Resource_Role__c','Account.Name'};
rsf.fieldsToSelect = flds;
/*
Use the skillsToSelect parameter to specify which Skills should have information (Skill Ratings) returned as part of the results.
This is not a filter operation. You can return information about skills independent from if they are filtered on or not.
The Skill Rating records pertaining to the requested skills are returned as a sub-query of the contacts.
*/
set<ID> skillIds = new set<ID>();
set<String> mySkills = new set<String>{'warp manifold maintenance','holodeck programming','dilithium recrystallization','replicator repair'};
List<pse__Skill_Certification__c> skills = [SELECT ID FROM pse__Skill_Certification__c WHERE Name IN :mySkills];
for (pse__Skill_Certification__c s : skills){skillIds.add(s.Id);}
rsf.skillsToSelect = skillIds;
/*
Use the assignments parameter to retrieve information about each resource's assignments as a sub query.
*/
pse.ResourceSearchService.Assignments asmts = new pse.ResourceSearchService.Assignments();
asmts.startDate = Date.Today();
asmts.endDate = Date.Today().addDays(30);
asmts.maxReturned = 10;
asmts.includeBillable = true;
asmts.includeNonbillable = true;
asmts.includeCredited = true;
asmts.includeExcluded = true;
asmts.includeExcludedFromPlanners = true;
asmts.fields = new Set<String>{'Id','Name','pse__Start_Date__c','pse__End_Date__c'};
rsf.assignments = asmts;
/*
Use the requests parameter to retrieve information about each resource's resource requests as a sub query.
*/
pse.ResourceSearchService.ResourceRequests rrs = new pse.ResourceSearchService.ResourceRequests();
rrs.startDate = Date.Today();
rrs.endDate = Date.Today().addDays(30);
rrs.useScheduleDates = true;
rrs.includeRequestsWithoutSchedules = true;
rrs.includeRequestsThatBecameAssignments = false;
rrs.maxReturned = 10;
rrs.includeExcludedFromPlanners = true;
rrs.fields = new Set<String>{'Id','Name','pse__Start_Date__c','pse__End_Date__c'};
rsf.requests = rrs;
/*
Use the enableFuzzyMatching parameter to return the 'best' resources that don't necessarily exactly match the search criteria.
The returned resources are sorted in order of best match - this ordering is controlled by the RSS Custom Settings. These
settings comprise field weightings (Resource Role, Region, Practice, Group and Custom Fields) and relative priorities of different
criteria (skills, availability and fields).
As an example of the sort order consider the scenario below.
Resource Search Service Custom Settings:
Role Weighting = Essential
Region Weighting = Ideal
Practice Weighting = Desirable
Group Weighting = Essential
Filter Fields Priority = 1
Skills Priority = 2
Availability Priority = 3
Resource Filter Values:
Role = Consultant
Region = United States
Practice = Consumer
Results:
All resources returned match on role and will be returned in the following order:
1. Resources who match on both region and practice.
2. Resources who match on region but not on practice.
3. Resources who match on practice but not region.
4. Resources who do not match on region or practice.
Within each ordered group, resources are ordered by skill rating and then by availability, as per the priority custom setting values above.
*/
rsf.enableFuzzyMatching = true;
/*
Use the orderByFields parameter to control the ordering of the search results. When fuzzy matching, the results are always ordered by best match and orderByFields is ignored.
*/
List<String> orderby = new List<String>{'Name'};
rsf.orderByFields = orderBy;
/*
Use the "maxReturnedResults" parameter to limit the results to a specific number of returned records.
The default value is 50000.
*/
rsf.maxReturnedResults = 999;
/*
*****************************************
******* Filtering Related Options *******
*****************************************
/*
/*
Use the additionalContactFilters parameter to specify additional filter criteria on the contact object. Optionally, the filter field can be set to fuzzy match,
meaning that the associated values are preferences and that selected resources do not have to match these values. Currently, the only filter field this applies
to is Resource Role.
*/
List<pse.ResourceSearchService.ResourceSearchFilterField> additionalContactFilters = new List<pse.ResourceSearchService.ResourceSearchFilterField>();
pse.ResourceSearchService.ResourceSearchFilterField rsff = new pse.ResourceSearchService.ResourceSearchFilterField();
rsff.field = Contact.pse__Resource_Role__c;
rsff.values = new Set<Object>{'Architect', 'Senior Developer'};
rsff.operator = 'IN'; //NOTE: When using "values" IN is the only valid operator, and is automatically elected.
rsff.fuzzyMatch = true; // Matches on role are preferred but not required.
additionalContactFilters.add(rsff);
rsff = new ResourceSearchService.ResourceSearchFilterField();
rsff.field = Contact.pse__Is_Resource__c;
rsff.value = true;
rsff.operator = '=';
additionalContactFilters.add(rsff);
rsff = new ResourceSearchService.ResourceSearchFilterField();
rsff.field = Contact.pse__Is_Resource_Active__c;
rsff.value = true;
rsff.operator = '=';
additionalContactFilters.add(rsff);
rsff = new ResourceSearchService.ResourceSearchFilterField();
rsff.field = Contact.pse__Start_Date__c;
rsff.value = Date.NewInstance(2015,1,1);
rsff.operator = '<';
additionalContactFilters.add(rsff);
rsff = new ResourceSearchService.ResourceSearchFilterField();
Use the additionalSemiJoinFilters to filter to resources who are members of specific sets.
Sets are defined via sObjects that have a relationship field to contact.
For example:
Assume we have a sObject called "Cool_Place__c" which is a list of exciting places where projects take place. (It has the standard Fields ID and Name).
We also have an sObject called "My_Wishlist__c" that allows resources to indicate the cool places they want to work at.
It has these fields: ID, Name, Resource__c (lookup to Contact), Place_I_Want_To_See__c (lookup to Cool_Place__c)
Our Project needs people in AUS or NZ, AND needs people in Spain. We will search for resources that want to work in (AUS OR NZ) AND (Spain).
Defines the configuration for location based filtering of resources and the calculation of the distance between the location of the resources and the requested location. If the value is null, location based filtering is ignored.
maxReturnedResults
Integer
Defines the maximum number of results to return.
fieldsToSelect
Set<String>
Specifies the Contact object fields to retrieve.
skillsToSelect
Set<ID>
Specifies the Skill records associated with the Contact to retrieve.
desirableSkills
Set<ID>
Specifies the Desirable Skills records to be used to calculate skill score for the filtered resource.
orderByFields
List<String>
Specifies the Contact object fields by which to sort the results. This is not considered by fuzzy matching.
Refines search results using filters defined in ResourceSearchFilterField. Filter values are <field><operator><value> or <field><operator><values> with SOQL operators valid for the field type and an appropriate value or values for the field type. When fuzzy matching is enabled and the filter is defined to be fuzzy, non-matching values can be returned from the SOQL query and weighted according to the user's preference. If the user preference indicates "Essential" then an exact match is performed.
Refines search results using related lists consisting of the related object, relationship field (the Resource (Contact) object), the field to search containing the relevant ID, and the ID.
A list of lists containing sets of skills. Each "skill set" (inner list) is an AND operation, while each member of the "skill set" (inner list) are "OR" operations.
applyStaffingPermissionControls
Boolean
If set to true, then Staffing permission controls are factored into the results and returns only resources the user has staffing permissions for.
resourceIds
Set<Id>
A set of resource Ids by which the search should be limited.
disableSharingModel
Boolean
If set to true, the API will bypass the Sharing Model.
disableSecurityOnReturnedData
Boolean
If set to true, then CRUD and field-level security (FLS) are applied to returned data fields. If set to false (default) an error is thrown if the user does not have the required permissions.
disableSecurityOnSearchCriteria
Boolean
If set to true, then CRUD and field-level security (FLS) are disabled for data fields used to filter results. If set to false (default) an error is thrown if the user does not have the required permissions.
regionFilter
ID
Searches for Resource records in a Region. Note that you cannot use this property in conjunction with regionsFilter.
regionsFilter
Set<ID>
Searches for Resource records in a set of Regions. Note that you cannot use this property in conjunction with regionFilter.
includeSubregions
Boolean
Includes sub-regions included under the Region(s) searched.
practiceFilter
ID
Searches for Resource records in a Practice. Note that you cannot use this property in conjunction with practicesFilter.
practicesFilter
Set<ID>
Searches for Resource records in a set of Practices. Note that you cannot use this property in conjunction with practiceFilter.
includeSubpractices
Boolean
Includes sub-practices included under the Practice searched.
groupFilter
ID
Searches for Resource records in a Group. Note that you cannot use this property in conjunction with groupsFilter.
groupsFilter
Set<ID>
Searches for Resource records in a set of Groups. Note that you cannot use this property in conjunction with groupFilter.
includeSubgroups
Boolean
Includes sub-groups included under the Group searched.
utilizationStartDate
Date
Specifies the start date for when you need the Resource.
utilizationEndDate
Date
Specifies the end date for when you need the Resource.
utilizationIncludeBillableAssignments
Boolean
Set to false to exclude billable assignments from the Resource search. By default, this value is true.
utilizationIncludeCreditedAssignments
Boolean
Set to false to exclude credited assignments from the Resource search. By default, this value is true.
utilizationIncludeExcludedAssignments
Boolean
Set to false to exclude excluded assignments from the Resource search. By default, this value is true.
utilizationIncludeNonBillableAssignments
Boolean
Set to false to exclude non-billable assignments from the Resource search. By default, this value is true.
utilizationIncludeHeldResourceRequests
Boolean
Set to false to exclude held resource requests from the Resource search. By default, this value is true.
utilizationMinimumHoursAvailable
Decimal
Specifies a numeric value specifying the minimum number hours. Note that you cannot use this property in conjunction with the utilizationNoMinimumAvailabilityRequirements global variable.
utilizationMinimumAvailability
Decimal
Specifies percentage of minimum availability. Note that you cannot use this property in conjunction with the utilizationNoMinimumAvailabilityRequirements global variable.
utilizationAppliedConjunctionAnd
Boolean
By default, if both utilizationMinimumHoursAvailable and utilizationMinimumAvailability are supplied then both conditions must be met. Set this value to false to retrieve resources that meet either condition. Note that you cannot use this property in conjunction with the utilizationNoMinimumAvailabilityRequirements global variable.
utilizationNoMinimumAvailabilityRequirements
Boolean
By default, you must supply either the utilizationMinimumHoursAvailable or the utilizationMinimumAvailability global variable to generate utilization data. Set this value to true to generate utilization data for all matching resources. Note that you cannot use this property in conjunction with the utilizationMinimumAvailability, utilizationMinimumAvailability, or utilizationAppliedConjunctionAnd global variables.
Retrieve assignments that are assigned to the Resource.
isAssigned
Boolean
When this variable is set to true, the API uses (data_assigned__c fields = true) to query the Utilization_Engine_TOD__c and returns the resources with assignments in the requested time frame global variable.
isCalendared
Boolean
When this variable is set to true, the API uses (data_calendar__c fields = true) to query the Utilization_Engine_TOD__c and returns the calendared resources who have working hours in the requested time frame global variable.
isHeld
Boolean
When this variable is set to true, the API uses (data_held__c fields = true) to query the Utilization_Engine_TOD__c and returns resources that have held resource request in the requested time frame global variable.
startTimeOfDay
DateTime
Specifies the start time of the day when you need the resource
endTimeOfDay
DateTime
Specifies the end time of the day when you need the resource
An optional configuration for fuzzy matching. This is only relevant when 'enableFuzzyMatching' is true. Any properties that are null will be populated from the corresponding RSS Custom Setting value.
workedWithCustomerBefore
Boolean
Flag to filter by resources who have/have not been assigned to a project for a specific Account Id.
workedWithCustomerAccId
Id
The ID of the account to be used in conjunction with workedWithCustomerBefore.
Defines a skill rating to be used in conjunction with skills filters.
Properties
Name
Type
Description
skillID
ID
The ID of the Skill for which to search
rating
String
The minimum skill rating required to qualify as a match. If null, matches are based on skill without evaluating specific ratings.
recordType
String
The record type of the Skill.
alternativeRatingField
sObjectField
The field from the Skill_Certification_Rating__c on which to search ratings. If null, the Rating__c field is used.
matchGreaterThanRatings
Boolean
Includes skill ratings greater than the specified rating. When false, searches for specified ratings must match the exact rating. Note that you cannot use this property in conjunction with operator or a null rating.
operator
String
Defines the operator. Must contain an appropriate value for the field (see the Salesforce SOQL Documentation for more about soql comparison operators). Note that you cannot use this property in conjunction with matchGreaterThanRatings or a null rating. If the rating is 'None', then the only valid operators are '=' (equal) or '!=' (not equal).
Defines configuration for 'fuzzy match' searches. Where values are not provided, values may be taken from the RSS Custom Settings.
Properties
Name
Type
Description
roleWeight
String
(Optional) The weight value to use when scoring a matching Role. Valid values are 'Essential', 'Ideal', 'Desirable' and 'Suggested'.
regionWeight
String
(Optional) The weight value to use when scoring a matching Region. Valid values are 'Essential', 'Ideal', 'Desirable' and 'Suggested'.
practiceWeight
String
(Optional) The weight value to use when scoring a matching Practice. Valid values are 'Essential', 'Ideal', 'Desirable' and 'Suggested'.
groupWeight
String
(Optional) The weight value to use when scoring a matching Group. Valid values are 'Essential', 'Ideal', 'Desirable' and 'Suggested'.
customFilterFieldsWeight
String
(Optional) The weight value to use when scoring a matching Custom Filter Field. Valid values are 'Essential', 'Ideal', 'Desirable' and 'Suggested'.
workedWithCustomerWeight
String
(Optional) The weight value to use when scoring a Resource in conjunction with the 'workedWithCustomerBefore' filter field. Valid values are 'Essential', 'Ideal', 'Desirable' and 'Suggested'.
Defines the configuration for location based filtering of resources and the calculation of the distance between the location of the resources and the requested location. If the value is null, location based filtering is ignored.
Properties
Name
Type
Description
requestedLocation
Location
Work location to staff the resource.
distanceThreshold
Decimal
The maximum limit of the distance between the location of the resource and the resource request site that can be returned in matches.
distanceUnit
String
The unit of distance specified in Kilometers(km) or Miles(mi).