Professional Services Automation Apex API Developer Reference

pse.UtilizationAnalyticsService

global with sharing class UtilizationAnalyticsService

This service provides the functionality relating to Utilization Analytics.

Methods

runUtilization

global static pse.UtilizationAnalyticsService.RunUtilizationResponse runUtilization()

Queues Utilization Analytics Apex jobs to asynchronously process objects required. For example, Timecards and Assignments.

Return Value

The result of the operation.

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.

pse.UtilizationAnalyticsService.RunUtilizationResponse response = pse.UtilizationAnalyticsService.runUtilization();
if (!response.errors.isEmpty()){
  System.debug('Errors: ' + response.errors);
}

runUtilization

global static pse.UtilizationAnalyticsService.RunUtilizationResponse runUtilization(Date startDate, Date endDate)

Queues Utilization Analytics Apex jobs to asynchronously process objects required. For example, Timecards and Assignments.

Input Parameters

Name Type Description
startDate Date Value to set the start date for the Utilization Analytics Apex job run.
endDate Date Value to set the end date for the Utilization Analytics Apex job run.

Return Value

The result of the operation.

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.

pse.UtilizationAnalyticsService.RunUtilizationResponse response = pse.UtilizationAnalyticsService.runUtilization(
  Date.newInstance(2023, 7, 1),
  Date.newInstance(2023, 7, 7)
);
if (!response.errors.isEmpty()){
  System.debug('Errors: ' + response.errors);
}

runUtilization

global static pse.UtilizationAnalyticsService.RunUtilizationResponse runUtilization(pse__Utilization_Setup__c setup)

Queues Utilization Analytics Apex jobs to asynchronously process objects required. For example, Timecards and Assignments.

Input Parameters

Name Type Description
setup pse__Utilization_Setup__c The instance of the Utilization Setup, used to derive parameters for the Utilization Analytics Apex job run.

Return Value

The result of the operation.

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.

Utilization_Setup__c setup = new Utilization_Setup__c();
pse.UtilizationAnalyticsService.RunUtilizationResponse response = pse.UtilizationAnalyticsService.runUtilization(setup);
if (!response.errors.isEmpty()){
  System.debug('Errors: ' + response.errors);
}

runUtilization

global static pse.UtilizationAnalyticsService.RunUtilizationResponse runUtilization(Id setupId)

Queues Utilization Analytics Apex jobs to asynchronously process objects required. For example, Timecards and Assignments.

Input Parameters

Name Type Description
setupId Id The ID of the Utilization Setup, used to derive parameters for the Utilization Analytics Apex job run.

Return Value

The result of the operation.

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.

Id setupId = [SELECT Id FROM pse__Utilization_Setup__c LIMIT 1][0].Id; 
pse.UtilizationAnalyticsService.RunUtilizationResponse response = pse.UtilizationAnalyticsService.runUtilization(setupId);
if (!response.errors.isEmpty()){
  System.debug('Errors: ' + response.errors);
}

runUtilizationForResource

global static pse.UtilizationAnalyticsService.RunUtilizationResponse runUtilizationForResource(Id resourceId)

Queues Utilization Analytics Apex jobs to asynchronously process for a specific resource.

Input Parameters

Name Type Description
resourceId Id The resource for which utilization will be calculated.

Return Value

The result of the operation.

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.

Id resourceId = [SELECT Id FROM Contact WHERE pse__Is_Resource__c = True LIMIT 1][0].Id; 
pse.UtilizationAnalyticsService.RunUtilizationResponse response = pse.UtilizationAnalyticsService.runUtilizationForResource(resourceId);
if (!response.errors.isEmpty()){
  System.debug('Errors: ' + response.errors);
}

runUtilizationForResource

global static pse.UtilizationAnalyticsService.RunUtilizationResponse runUtilizationForResource(Id resourceId, Date startDate, Date endDate)

Queues Utilization Analytics Apex jobs to asynchronously process for a specific resource, between specific dates.

Input Parameters

Name Type Description
resourceId Id The resource for which utilization will be calculated.
startDate Date Value to set the start date for the Utilization Analytics Apex job run.
endDate Date Value to set the end date for the Utilization Analytics Apex job run.

Return Value

The result of the operation.

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.

Id resourceId = [SELECT Id FROM Contact WHERE pse__Is_Resource__c = True LIMIT 1][0].Id; 
pse.UtilizationAnalyticsService.RunUtilizationResponse response = pse.UtilizationAnalyticsService.runUtilizationForResource(
  resourceId,
  Date.newInstance(2023, 7, 1),
  Date.newInstance(2023, 7, 7)
);
if (!response.errors.isEmpty()){
  System.debug('Errors: ' + response.errors);
}

runUtilizationForRole

global static pse.UtilizationAnalyticsService.RunUtilizationResponse runUtilizationForRole(String roleName)

Queues Utilization Analytics Apex jobs to asynchronously process for a specific role.

Input Parameters

Name Type Description
roleName String The role for which utilization will be calculated.

Return Value

The result of the operation.

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.

pse.UtilizationAnalyticsService.RunUtilizationResponse response = pse.UtilizationAnalyticsService.runUtilizationForRole('Trainer');
if (!response.errors.isEmpty()){
  System.debug('Errors: ' + response.errors);
}

runUtilizationForRole

global static pse.UtilizationAnalyticsService.RunUtilizationResponse runUtilizationForRole(String roleName, Date startDate, Date endDate)

Queues Utilization Analytics Apex jobs to asynchronously process for a specific role, between specific dates.

Input Parameters

Name Type Description
roleName String The role for which utilization will be calculated.
startDate Date Value to set the start date for the Utilization Analytics Apex job run.
endDate Date Value to set the end date for the Utilization Analytics Apex job run.

Return Value

The result of the operation.

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.

pse.UtilizationAnalyticsService.RunUtilizationResponse response = pse.UtilizationAnalyticsService.runUtilizationForRole(
  'Trainer',
  Date.newInstance(2023, 7, 1),
  Date.newInstance(2023, 7, 7)
);
if (!response.errors.isEmpty()){
  System.debug('Errors: ' + response.errors);
}

isUtilizationAnalyticsTransaction

global static Boolean isUtilizationAnalyticsTransaction()

Checks if the current transaction is running in the Utilization Analytics context. Can be used within a trigger on the Assignment or Resource Request SObject to return early as no additional processing should be carried out when running in the Utilization Analytics context.

Return Value

True if the current transaction is running in the Utilization Analytics context.

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.

trigger CustomAssignmentTrigger on pse__Assignment__c (before insert, before update) {
    if (pse.UtilizationAnalyticsService.isUtilizationAnalyticsTransaction()) {
        return;
    }

    for (Assignment__c assignment : Trigger.new) {
        assignment.addError('An error occurred');
    }
}

pse.UtilizationAnalyticsService.RunUtilizationResponse

global inherited sharing class RunUtilizationResponse

The response structure from creating a utilization run.

Properties

Name Type Description
utilizationRunId Id The Id of the Utilization run.
errors List<String> A list of the errors encountered by the Utilization Analytics service call.

Methods

RunUtilizationResponse

global RunUtilizationResponse()

A constructor that creates a new RunUtilizationResponse instance.

© Copyright 2009–2023 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.