Professional Services Automation Apex API Developer Reference

pse.RateCardMatcherPlugin

global with sharing class RateCardMatcherPlugin

A class that contains plugins for rate card matching.

pse.RateCardMatcherPlugin.IFinalRateCardChoicePlugin

global interface IFinalRateCardChoicePlugin

Provides an interface that can be used to create plugins to be executed during the matching of rate cards. The plugins customize how the best matching rate cards are chosen. To set up a plugin, create a fferpcore__Plugin__mdt record with a fferpcore__ExtensionPoint__c of pse.RateCardMatcherPlugin.IFinalRateCardChoicePlugin, and a fferpcore__ClassName__c that matches an Apex class that implements that interface.

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.

/**
 * This final rate card choice plugin example uses a custom Level field on the Resource Request and Rate Card
 * objects to choose the rate card to match to each resource request. It will only use an exact match for
 * the Level field. It ignores any other records that can have rate cards matched to them such as
 * assignments and project task assignments.
 */
global with sharing class RateCardLevelPlugin implements pse.RateCardMatcherPlugin.IFinalRateCardChoicePlugin {
    global List<pse.RateCardMatcherPlugin.FinalRateCardChoiceResponse> chooseRateCards(
        List<pse.RateCardMatcherPlugin.FinalRateCardChoiceRequest> requests
    ) {
        // Gather the rate cards and resource requests to query for the custom Level field.
        // Custom fields are not included on the rate cards and records passed into the plugin
        // so they must be queried.
        Set<Id> rateCardIds = new Set<Id>();
        Set<Id> resourceRequestIds = new Set<Id>();
        for (pse.RateCardMatcherPlugin.FinalRateCardChoiceRequest request : requests) {
            for (pse__Rate_Card__c rateCard : request.getRateCardsToChooseFrom()) {
                rateCardIds.add(rateCard.Id);
            }

            switch on request.getRecord() {
                when pse__Resource_Request__c resourceRequest {
                    resourceRequestIds.add(resourceRequest.Id);
                }
                when pse__Assignment__c assignment {
                    // Custom rate card matching logic for assignments can be implemented here. In this
                    // plugin implementation, assignments are ignored.
                }
            }
        }

        // Select the custom Level__c fields on both rate card and resource request to use them
        // to find a match.
        Map<Id, pse__Rate_Card__c> rateCardWithLevelById = new Map<Id, pse__Rate_Card__c>(
            [SELECT Id, Level__c FROM pse__Rate_Card__c WHERE Id IN :rateCardIds]
        );
        Map<Id, pse__Resource_Request__c> resourceRequestWithLevelById = new Map<Id, pse__Resource_Request__c>(
            [SELECT Id, Level__c FROM pse__Resource_Request__c WHERE Id IN :resourceRequestIds]
        );

        List<pse.RateCardMatcherPlugin.FinalRateCardChoiceResponse> responses = new List<pse.RateCardMatcherPlugin.FinalRateCardChoiceResponse>();

        for (pse.RateCardMatcherPlugin.FinalRateCardChoiceRequest request : requests) {
            // Add a response to the list for every request so that the response list matches the
            // request list. Responses that do not have a chosen rate card set will not populate
            // the rates on the record.
            pse.RateCardMatcherPlugin.FinalRateCardChoiceResponse response = new pse.RateCardMatcherPlugin.FinalRateCardChoiceResponse();
            responses.add(response);

            switch on request.getRecord() {
                when pse__Resource_Request__c resourceRequest {
                    String resourceRequestLevel = resourceRequestWithLevelById.get(
                            resourceRequest.Id
                        )
                        .Level__c;

                    for (pse__Rate_Card__c rateCard : request.getRateCardsToChooseFrom()) {
                        // All other matching parameters including Start Date, Resource Role,
                        // Account, Region, Practice, and Group have already been applied. The rate
                        // cards to choose from are equally matched according to those parameters.
                        String rateCardLevel = rateCardWithLevelById.get(rateCard.Id).Level__c;

                        if (resourceRequestLevel == rateCardLevel) {
                            // If there is an exact match on the Level field choose the Rate Card.
                            response.setChosenRateCard(rateCard);

                            // Assume there will only be one rate card that matches for each resource request.
                            break;
                        }
                    }
                }
            }
        }

        return responses;
    }
}

Methods

chooseRateCards

List<FinalRateCardChoiceResponse> chooseRateCards(List<pse.RateCardMatcherPlugin.FinalRateCardChoiceRequest> requests)

A method that chooses the best rate card for a record from a set of rate cards.

Input Parameters

Name Type Description
requests List<pse.RateCardMatcherPlugin.FinalRateCardChoiceRequest> A list of RateCardMatcherPlugin.FinalRateCardChoiceRequest.

Return Value

A list of RateCardMatcherPlugin.FinalRateCardChoiceResponse that parallels the list of requests.

pse.RateCardMatcherPlugin.FinalRateCardChoiceRequest

global with sharing class FinalRateCardChoiceRequest

The request structure for choosing a rate card to match to a record.

Methods

getRecord

global SObject getRecord()

Returns the record that rate cards are being matched to.

Return Value

The record to match rate cards to.

getRateCardsToChooseFrom

global Set<pse__Rate_Card__c> getRateCardsToChooseFrom()

Returns the set of rate cards to choose from to match to the record.

Return Value

The set of rate cards to choose from to match to the record.

pse.RateCardMatcherPlugin.FinalRateCardChoiceResponse

global with sharing class FinalRateCardChoiceResponse

The response structure for choosing a rate card to match to a record.

Methods

FinalRateCardChoiceResponse

global FinalRateCardChoiceResponse()

setChosenRateCard

global void setChosenRateCard(pse__Rate_Card__c chosenRateCard)

Sets the rate card chosen from the set of rate cards provided in the request.

Input Parameters

Name Type Description
chosenRateCard pse__Rate_Card__c The rate card chosen from the set of rate cards.
© Copyright 2009–2023 Certinia Inc. All rights reserved. Various trademarks held by their respective owners.