ffscpq.RateCardMatcherPluginglobal with sharing class RateCardMatcherPlugin A class that contains plugins for rate card matching. ffscpq.RateCardMatcherPlugin.IFinalRateCardChoicePluginglobal 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 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 Estimate Role Request and Rate Card * objects to choose the rate card to match to each estimate role request. It will only use an exact match for * the Level field. */ global with sharing class RateCardLevelPlugin implements ffscpq.RateCardMatcherPlugin.IFinalRateCardChoicePlugin { global List<ffscpq.RateCardMatcherPlugin.FinalRateCardChoiceResponse> chooseRateCards( List<ffscpq.RateCardMatcherPlugin.FinalRateCardChoiceRequest> requests ) { // Gather the rate cards and role 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> estimateRoleRequestIds = new Set<Id>(); for (ffscpq.RateCardMatcherPlugin.FinalRateCardChoiceRequest request : requests) { for (pse__Rate_Card__c rateCard : request.getRateCardsToChooseFrom()) { rateCardIds.add(rateCard.Id); } switch on request.getRecord() { when ffscpq__Estimate_Role_Request__c estimateRoleRequest { estimateRoleRequestIds.add(estimateRoleRequest.Id); } } } // Select the custom Level__c fields on both rate card and role 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, ffscpq__Estimate_Role_Request__c> estimateRoleRequestsWithLevelById = new Map<Id, ffscpq__Estimate_Role_Request__c>( [ SELECT Id, Level__c FROM ffscpq__Estimate_Role_Request__c WHERE Id IN :estimateRoleRequestIds ] ); List<ffscpq.RateCardMatcherPlugin.FinalRateCardChoiceResponse> responses = new List<ffscpq.RateCardMatcherPlugin.FinalRateCardChoiceResponse>(); for (ffscpq.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. ffscpq.RateCardMatcherPlugin.FinalRateCardChoiceResponse response = new ffscpq.RateCardMatcherPlugin.FinalRateCardChoiceResponse(); responses.add(response); switch on request.getRecord() { when ffscpq__Estimate_Role_Request__c estimateRoleRequest { // If the estimate role request in the request has a Level use that. // Otherwise use the Level value of the saved version of the record. String estimateRoleRequestLevel = estimateRoleRequest.isSet( ffscpq__Estimate_Role_Request__c.Level__c ) ? estimateRoleRequest.Level__c : estimateRoleRequestsWithLevelById.get(estimateRoleRequest.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 (estimateRoleRequestLevel == 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 role request. break; } } } } } return responses; } } MethodschooseRateCardsList<FinalRateCardChoiceResponse> chooseRateCards(List<ffscpq.RateCardMatcherPlugin.FinalRateCardChoiceRequest> requests) A method that chooses the best rate card for a record from a set of rate cards. Input Parameters
Return ValueA list of RateCardMatcherPlugin.FinalRateCardChoiceResponse that parallels the list of requests. ffscpq.RateCardMatcherPlugin.FinalRateCardChoiceRequestglobal with sharing class FinalRateCardChoiceRequest MaxDependencyCount(1) MethodsgetRecordglobal SObject getRecord() Returns the record that rate cards are being matched to. Return ValueThe record to match rate cards to. getRateCardsToChooseFromglobal Set<pse__Rate_Card__c> getRateCardsToChooseFrom() Returns the set of rate cards to choose from to match to the record. Return ValueThe set of rate cards to choose from to match to the record. ffscpq.RateCardMatcherPlugin.FinalRateCardChoiceResponseglobal with sharing class FinalRateCardChoiceResponse MaxDependencyCount(1) Methods
FinalRateCardChoiceResponseglobal FinalRateCardChoiceResponse() setChosenRateCardglobal void setChosenRateCard(pse__Rate_Card__c chosenRateCard) Sets the rate card chosen from the set of rate cards provided in the request. Input Parameters
|