pse.ResourceSearchServiceglobal with sharing class ResourceSearchService implements API A service that Queries the Resource (Contact) object using filters for security controls, region/practice/group, skills, utilization, and others. Methods
executeglobal 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. Input Parameters
Return ValueReturns a list of Contact records with the requested fields and skills, and optionally additional utilization related fields. Sample Code//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 disbleSharingModel 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 orderByFields parameter to control the ordering of the search results. */ 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 10000. */ rsf.maxReturnedResults = 999; /* ***************************************** ******* Filtering Related Options ******* ***************************************** /* /* Use the additionalContactFilters parameter to specify additional filter criteria on the contact object. */ 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. 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(); rsff.field = Contact.pse__Default_Cost_Rate__c; rsff.value = 125.00; rsff.operator = '>='; additionalContactFilters.add(rsff); rsf.additionalContactFilters = additionalContactFilters; /* Use the skillSets parameter to find resources with specific skills at specified ratings. SkillSets is a list of a list of SkillRating. Each member of the inner list are joined with an "or", and each member of the outer list are joined with an "and". For our example, find resources with: HTML4(>=Level4) OR HTML5(>=Level3) OR CSS(>=Level2) AND Java(=Level3) AND English Speaking(=Passing) OR English Writing (=Passing) Note: For our example the English skills use a custom alternative rating field. */ //Obtain the needed skills by some method. pse__Skill__c skillHTML4 = [SELECT ID FROM pse__Skill__c WHERE Name = 'HTML4']; pse__Skill__c skillHTML5 = [SELECT ID FROM pse__Skill__c WHERE Name = 'HTML5']; pse__Skill__c skillCSS = [SELECT ID FROM pse__Skill__c WHERE Name = 'CSS']; pse__Skill__c skillJAVA = [SELECT ID FROM pse__Skill__c WHERE Name = 'Java']; pse__Skill__c skillEngS = [SELECT ID FROM pse__Skill__c WHERE Name = 'English Speaking']; pse__Skill__c skillEngW = [SELECT ID FROM pse__Skill__c WHERE Name = 'English Writing']; pse.ResourceSearchService.SkillRating rssSR; list<pse.ResourceSearchService.SkillRating> rssSkillSet; list<list<pse.ResourceSearchService.SkillRating>> rssSkillSets = new list<list<pse.ResourceSearchService.SkillRating>>(); //HTML4 or HTML5 or CSS rssSkillSet = new list<pse.ResourceSearchService.SkillRating>(); rssSR = new pse.ResourceSearchService.SkillRating(); rssSR.skillID = skillHTML4.Id; rssSR.rating = 'Level4'; rssSR.matchGreaterThanRatings = true; rssSkillSet.add(rssSR); rssSR = new pse.ResourceSearchService.SkillRating(); rssSR.skillID = skillHTML5.Id; rssSR.rating = 'Level3'; rssSR.matchGreaterThanRatings = true; rssSkillSet.add(rssSR); rssSR = new pse.ResourceSearchService.SkillRating(); rssSR.skillID = skillCSS.Id; rssSR.rating = 'Level2'; rssSR.matchGreaterThanRatings = true; rssSkillSet.add(rssSR); rssSkillSets.add(rssSkillSet); //Java rssSkillSet = new list<pse.ResourceSearchService.SkillRating>(); rssSR = new pse.ResourceSearchService.SkillRating(); rssSR.skillID = skillJAVA.Id; rssSR.rating = 'Level3'; rssSR.operator = '='; //Only Level3 Java Programmers, not more advanced, not less advanced rssSkillSet.add(rssSR); rssSkillSets.add(rssSkillSet); //English Speaking OR English Writing rssSkillSet = new list<pse.ResourceSearchService.SkillRating>(); rssSR = new pse.ResourceSearchService.SkillRating(); rssSR.skillID = skillEngS.Id; rssSR.rating = 'Passing'; rssSR.alternativeRatingField = pse__Skill_Rating__c.Picklist_Pass_Fail__c; rssSR.operator = '='; rssSkillSet.add(rssSR); rssSR = new pse.ResourceSearchService.SkillRating(); rssSR.skillID = skillEngW.Id; rssSR.rating = 'Passing'; rssSR.alternativeRatingField = pse__Skill_Rating__c.Picklist_Pass_Fail__c; rssSR.operator = '='; rssSkillSet.add(rssSR); rssSkillSets.add(rssSkillSet); //Set the parameter rsf.skillSets = rssSkillSets; /* Limit to Regions/Practices/Groups NOTE: you can use regionFilter, practiceFilter, groupFilter for a single ID, or use the plural versions for filtering to a set of IDs. */ List<pse__Region__c> regions = [SELECT ID FROM pse__Region__c WHERE name IN ('California','Oregon','Washington')]; Set<Id> regionIds = new Set<Id>(); for( pse__Region__c r : regions ) regionIds.add( r.Id ); rsf.regionsFilter = regionIds; rsf.IncludeSubregions = true; //Include resources in sub-regions such as Norther California and Souther California and Bay Area pse__Practice__c practice = [SELECT ID FROM pse__Practice__c WHERE name = 'Web Development']; rsf.practiceFilter = practice.Id; rsf.IncludeSubpractices = true; //Include resources in sub-practices such as IIS or Apache/Tomcat or IBM Websphere List<pse__Grp__c> groups = [SELECT ID FROM pse__Grp__c WHERE name IN ('Waterfall','Agile')]; Set<Id> groupIds = new Set<Id>(); for( pse__Grp__c g : groups ) groupIds.add( g.Id ); rsf.groupsFilter = groupIds; rsf.IncludeSubgroups = false; //Not interested in sub groups of Waterfall or Agile /* Utilization Options. The set of utilization filtering options allow searching for resources with specific availability over a specified time range. The utilizationStartDate and utilizationEndDate parameters define the range of dates over which to calculate the resource availability. The following parameters control which types of assignments and resource requests are considered in the tabulation of utilization/availability: utilizationIncludeBillableAssignments utilizationIncludeCreditedAssignments utilizationIncludeExcludedAssignments utilizationIncludeNonBillableAssignments utilizationIncludeHeldResourceRequests Note: The work calendar hours are always considered in the calculation. These parameters control the criteria applied to the availability calculation for filtering the results: utilizationMinimumHoursAvailable utilizationMinimumAvailability utilizationAppliedConjunctionAnd utilizationNoMinimumAvailabilityRequirements */ /* In this example, we need someone for the months of June and July of 2017. */ rsf.utilizationStartDate = Date.newInstance(2017,6,1); rsf.utilizationEndDate = Date.newInstance(2017,7,31); /* Only consider billable assignments and held resource requests. This is a high priority project and thus credited/excluded/nonbillable assignments will be rescheduled to accommodate it. */ rsf.utilizationIncludeBillableAssignments = true; rsf.utilizationIncludeCreditedAssignments = false; rsf.utilizationIncludeExcludedAssignments = false; rsf.utilizationIncludeNonBillableAssignments = false; rsf.utilizationIncludeHeldResourceRequests = true; /* Find me resources with 160 available hours (or more) AND who are 50% or more available Search by either Hours or Percent Availability or by both and indicate if "AND" or "OR" should be applied when using both conditions. */ rsf.utilizationMinimumHoursAvailable = 160; rsf.utilizationMinimumAvailability = 0.50; rsf.utilizationAppliedConjunctionAnd = true; //Set this to false to find resource that are either (OR) condition. /* Set this option to true when you want to have the API calculate availability information for the time range, but not enforce any filtering. The availability information is returned in the results. */ rsf.utilizationNoMinimumAvailabilityRequirements = false; /* 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). */ list<pse.ResourceSearchService.SemiJoinFilter> rssSemiJoinFilters = new list<pse.ResourceSearchService.SemiJoinFilter>(); pse.ResourceSearchService.SemiJoinFilter sjf; //Add "AND" (AUS or NZ) List<Cool_Place__c> places1 = [SELECT ID FROM Cool_Place__c WHERE Name IN ('AUS','NZ')]; set<ID> placeIds1 = new Set<ID>(); for (Cool_Place__c cp : places1) placeIds1.add(cp.Id); sjf = new pse.ResourceSearchService.SemiJoinFilter(); sjf.relatedObject = My_Wishlist__c.getSObjectType(); sjf.relationshipField = My_Wishlist__c.Resource__c; sjf.searchField = My_Wishlist__c.Place_I_Want_To_See__c; sjf.values = placeIds1; rssSemiJoinFilters.add(sjf); //Add "AND" Spain List<Cool_Place__c> places2 = [SELECT ID FROM Cool_Place__c WHERE Name IN ('Spain')]; set<ID> placeIds2 = new Set<ID>(); for (Cool_Place__c cp : places2) placeIds2.add(cp.Id); sjf = new pse.ResourceSearchService.SemiJoinFilter(); sjf.relatedObject = My_Wishlist__c.getSObjectType(); sjf.relationshipField = My_Wishlist__c.Resource__c; sjf.searchField = My_Wishlist__c.Place_I_Want_To_See__c; sjf.values = placeIds2; rssSemiJoinFilters.add(sjf); //Set the filter parameter rsf.additionalSemiJoinFilters = rssSemiJoinFilters; // ************************* // ********CALL API********* // ************************* list<Contact> resources = ResourceSearchService.execute(rsf); // ************************* // *****Get Debug Info****** // ************************* debug = ResourceSearchService.debug(); debugglobal static String debug() The debug method provides diagnostic information about the status of the generated query. Return ValueReturns a string containing the generated queries and any error messages pse.ResourceSearchService.ResourceSearchFilterglobal class ResourceSearchFilter Used to define the criteria to be used by the resource search API execute method. Properties
Methodspse.ResourceSearchService.ResourceSearchFilterFieldglobal class ResourceSearchFilterField Defines the Resource fields to use as filters for the search. Properties
Methods
ResourceSearchFilterFieldglobal ResourceSearchFilterField(sObjectField field, String operator, Object value) A general constructor that takes the default fields Input Parameters
ResourceSearchFilterFieldglobal ResourceSearchFilterField(sObjectField field, Set<Object> values) A constructor that takes a field and a set of values to which that field must belong Input Parameters
pse.ResourceSearchService.SemiJoinFilterglobal class SemiJoinFilter Defines a related list to be used as a filter in the search. Properties
Methods
SemiJoinFilterglobal SemiJoinFilter(sObjectType relatedObject, sObjectField relationshipField, sObjectField searchField, Set<Id> values) A general constructor taking all parameters Input Parameters
pse.ResourceSearchService.SkillRatingglobal class SkillRating Defines a skill rating to be used in conjunction with skills filters. Properties
Methods
SkillRatingglobal SkillRating(ID skillID, String rating) A constructor taking the Skill ID and Skill Rating values. Input Parameters
SkillRatingglobal SkillRating(ID skillID, String rating, sObjectField alternativeRatingField, Boolean matchGreaterThanRatings) A constructor using the Skill ID, Skill Rating, Alternative Rating Field, and Match Greater Than Rating values. Input Parameters
SkillRatingglobal SkillRating(ID skillID, String rating, sObjectField alternativeRatingField, Boolean matchGreaterThanRatings, String operator) A constructor using the Skill ID, Skill Rating, Alternative Rating Field, Match Greater Than Rating, and Operator values. Input Parameters
pse.ResourceSearchService.Assignmentsglobal class Assignments Retrieve assignments that are assigned to the Resource. Properties
Methods
Assignmentsglobal Assignments(Date startDate, Date endDate, Integer maxReturned) A constructor taking the startDate, endDate, and maxReturned values. Input Parameters
Assignmentsglobal Assignments(Date startDate, Date endDate, Integer maxReturned, Set<String> fields) A constructor taking the startDate, endDate, maxReturned, and fields values. Input Parameters
Assignmentsglobal Assignments(Date startDate, Date endDate, Integer maxReturned, Boolean includeBillable, Boolean includeNonbillable, Boolean includeCredited, Boolean includeExcluded, Set<String> fields) A constructor taking the startDate, endDate, maxReturned, includeBillable, includeCredited, includeExcluded, and fields values. Input Parameters
pse.ResourceSearchService.ResourceRequestsglobal class ResourceRequests Retrieve held resource requests that are assigned to the Resource. Properties
Methods
ResourceRequestsglobal ResourceRequests(Date startDate, Date endDate, Integer maxReturned) A constructor taking the startDate, endDate, and maxReturned values. Input Parameters
ResourceRequestsglobal ResourceRequests(Date startDate, Date endDate, Integer maxReturned, Set<String> fields) A constructor taking the startDate, endDate, maxReturned, and fields values. Input Parameters
ResourceRequestsglobal ResourceRequests(Date startDate, Date endDate, Integer maxReturned, Boolean includeRequestsWithoutSchedules, Boolean includeRequestsThatBecameAssignments, Set<String> fields) A constructor taking the startDate, endDate, maxReturned, includeRequestsWithoutSchedules, includeRequestsThatBecameAssignments and fields values. Input Parameters
|