Professional Services Automation Apex API Developer Reference

pse.ServicesCreditsService

global with sharing class ServicesCreditsService

This class contains methods to manage the allocation, adjustment, and expiry of services credits.

Methods

allocateCreditsForMilestones

global static pse.ServicesCreditsService.ServicesCreditsAllocationResponse allocateCreditsForMilestones(pse.ServicesCreditsService.ServicesCreditsAllocationRequest request)

Allocates available services credits to the given milestones.

Input Parameters

Name Type Description
request pse.ServicesCreditsService.ServicesCreditsAllocationRequest Structure containing the IDs of milestones to be allocated.

Return Value

This method returns an object containing a list of objects representing the results. Each object is the result for one milestone, containing the milestone ID, and the ID of the created allocation record.

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.

//construct the request object
List<Id> milestoneIds = new List<Id>{'a1r000000000001AAA', 'a1r000000000002AAA', 'a1r000000000003AAA'};
pse.ServicesCreditsService.ServicesCreditsAllocationRequest request = new pse.ServicesCreditsService.ServicesCreditsAllocationRequest(milestoneIds);

//call the service
pse.ServicesCreditsService.ServicesCreditsAllocationResponse response = pse.ServicesCreditsService.allocateCreditsForMilestones(request);

//read the response object
pse.ServicesCreditsService.ServicesCreditsAllocationResult firstResult = response.results[0];
Id firstAllocationId = firstResult.allocationId;

manuallyAllocateCreditsForMilestones

global static pse.ServicesCreditsService.ManualAllocationResponse manuallyAllocateCreditsForMilestones(List<pse.ServicesCreditsService.ManualAllocationRequest> allocationRequests)

Allocates available services credits to the given milestones.

Input Parameters

Name Type Description
allocationRequests List<pse.ServicesCreditsService.ManualAllocationRequest> List of requests for manual allocation of an individual milestone.

Return Value

This method returns an object containing a map of the milestone ID for which the process was called for to an object containing the result for that milestone. The result object contains the milestone ID and the ID of the allocation record created.

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.

List<Id> milestoneIdsToAllocate = new List<Id>{'a1r000000000001AAA', 'a1r000000000002AAA'};
List<Id> purchaseIdsToConsume = new List<Id>{'a2y000000000001AAA', 'a2y000000000002AAA'};

//create a request object for each milestone, with the credits to consume from each purchase
Map<Id, Integer> creditsToConsumePerPurchaseForMilestone1 = new Map<Id, Integer>{
    purchaseIdsToConsume[0] => 30,
    purchaseIdsToConsume[1] => 10
};
pse.ServicesCreditsService.ManualAllocationRequest req1 = new pse.ServicesCreditsService.ManualAllocationRequest(
    creditsToConsumePerPurchaseForMilestone1,
    milestoneIdsToAllocate[0]
);

Map<Id, Integer> creditsToConsumePerPurchaseForMilestone2 = new Map<Id, Integer>{
    purchaseIdsToConsume[1] => 20
};
pse.ServicesCreditsService.ManualAllocationRequest req2 = new pse.ServicesCreditsService.ManualAllocationRequest(
    creditsToConsumePerPurchaseForMilestone2,
    milestoneIdsToAllocate[1]
);

//run the manual allocation
pse.ServicesCreditsService.ManualAllocationResponse response = pse.ServicesCreditsService.manuallyAllocateCreditsForMilestones(
    new List<pse.ServicesCreditsService.ManualAllocationRequest>{ req1, req2 }
);

//the results can be accessed from the response
Map<Id, pse.ServicesCreditsService.ManualAllocationResult> results = response.results;
pse.ServicesCreditsService.ManualAllocationResult result = results.get(milestoneIdsToAllocate[0]);

adjustCreditsForMilestones

global static pse.ServicesCreditsService.ServicesCreditsAdjustmentResponse adjustCreditsForMilestones(pse.ServicesCreditsService.ServicesCreditsAdjustmentRequest request)

Adjusts number of services credits on given milestones to the given number.

Input Parameters

Name Type Description
request pse.ServicesCreditsService.ServicesCreditsAdjustmentRequest Structure containing a map of milestone IDs to the number of credits to adjust to.

Return Value

This method currently returns an empty object which is reserved for future use.

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.

//construct the request object
Map<Id,Integer> milestoneIdsToNewCredits = new Map<Id,Integer>{'a1r000000000001AAA'=> 100, 'a1r000000000002AAA'=>50, 'a1r000000000003AAA'=>75};
pse.ServicesCreditsService.ServicesCreditsAdjustmentRequest request = new pse.ServicesCreditsService.ServicesCreditsAdjustmentRequest(milestoneIdsToNewCredits);
 
//call the service
pse.ServicesCreditsService.ServicesCreditsAdjustmentResponse response = pse.ServicesCreditsService.adjustCreditsForMilestones(request);

manuallyAdjustCreditsForMilestones

global static pse.ServicesCreditsService.ManualAdjustmentResponse manuallyAdjustCreditsForMilestones(List<pse.ServicesCreditsService.ManualAdjustmentRequest> adjustmentRequests)

Adjusts services credits to the given milestones.

Input Parameters

Name Type Description
adjustmentRequests List<pse.ServicesCreditsService.ManualAdjustmentRequest> List of requests for manual adjustment of an individual milestone.

Return Value

This method currently returns an empty object which is reserved for future use.

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.

List<Id> milestoneIdsToAdjust = new List<Id>{'a1r000000000001AAA', 'a1r000000000002AAA'};
List<Id> purchaseIdsToAdjust = new List<Id>{'a2y000000000001AAA', 'a2y000000000002AAA'};

//create a request object for each milestone, with the credits to adjust from each purchase
Map<Id, Integer> creditsToAdjustPerPurchaseForMilestone1 = new Map<Id, Integer>{
    purchaseIdsToAdjust[0] => 10,
    purchaseIdsToAdjust[1] => -20
};
pse.ServicesCreditsService.ManualAdjustmentRequest req1 = new pse.ServicesCreditsService.ManualAdjustmentRequest(
    creditsToAdjustPerPurchaseForMilestone1,
    milestoneIdsToAdjust[0]
);

Map<Id, Integer> creditsToAdjustPerPurchaseForMilestone2 = new Map<Id, Integer>{
    purchaseIdsToAdjust[1] => 30
};
pse.ServicesCreditsService.ManualAdjustmentRequest req2 = new pse.ServicesCreditsService.ManualAdjustmentRequest(
    creditsToAdjustPerPurchaseForMilestone2,
    milestoneIdsToAdjust[1]
);

//run the manual adjustment
pse.ServicesCreditsService.ManualAdjustmentResponse response = pse.ServicesCreditsService.manuallyAdjustCreditsForMilestones(
    new List<pse.ServicesCreditsService.ManualAdjustmentRequest>{ req1, req2 }
);

expireCreditsForPurchase

global static pse.ServicesCreditsService.ExpireCreditsForPurchaseResponse expireCreditsForPurchase(pse.ServicesCreditsService.ExpireCreditsForPurchaseRequest request)

A method that expires Services Credits Customer Purchases. Partial success is allowed.

Input Parameters

Name Type Description
request pse.ServicesCreditsService.ExpireCreditsForPurchaseRequest Structure containing the IDs of Services Credits Customer Purchases to be expired.

Return Value

ExpireCreditsForPurchaseResponse Structure containing a map of Services Credits Customer Purchase Id to expiry result.

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.

//construct the request object
List<Id> purchaseIds = new List<Id>{'a1r000000000001AAA', 'a1r000000000002AAA', 'a1r000000000003AAA'};
pse.ServicesCreditsService.ExpireCreditsForPurchaseRequest request = new pse.ServicesCreditsService.ExpireCreditsForPurchaseRequest(purchaseIds);

//call the service
pse.ServicesCreditsService.ExpireCreditsForPurchaseResponse response = pse.ServicesCreditsService.expireCreditsForPurchase(request);

//response if successful
pse.ServicesCreditsService.ServicesCreditsExpiryResult firstResult = response.resultsMap.get('a1r000000000001AAA');
Id firstAllocationId = firstResult.allocationId; // this will be populated
String errorMessage = firstResult.errorMessage; // this will be null

//response if there was an error
pse.ServicesCreditsService.ServicesCreditsExpiryResult secondResult = response.resultsMap.get('a1r000000000001AAA');
Id secondAllocationId = secondResult.allocationId; // this would be null
String errorMessage = secondResult.errorMessage; // this will be populated

pse.ServicesCreditsService.ServicesCreditsAllocationResult

global with sharing class ServicesCreditsAllocationResult

The result of allocation for a single milestone.

Properties

Name Type Description
allocationId Id The ID of the allocation record that was created.
milestoneId Id The ID of the milestone associated with this result.

pse.ServicesCreditsService.ServicesCreditsAllocationRequest

global with sharing class ServicesCreditsAllocationRequest

A structure containing the List of milestone IDs to allocate.

Properties

Name Type Description
milestones List<Id> The List of IDs of the milestones to allocate.

Methods

ServicesCreditsAllocationRequest

global ServicesCreditsAllocationRequest(List<Id> milestones)

pse.ServicesCreditsService.ServicesCreditsAllocationResponse

global with sharing class ServicesCreditsAllocationResponse

A structure containing the results of allocateCreditsForMilestones

Properties

Name Type Description
results List<pse.ServicesCreditsService.ServicesCreditsAllocationResult> The results of the allocation for each milestone. Each object is the result for one milestone.

pse.ServicesCreditsService.ManualAllocationResult

global with sharing class ManualAllocationResult

The result of manual allocation for a single milestone.

Properties

Name Type Description
allocationId Id The ID of the allocation record that was created.
milestoneId Id The ID of the milestone associated with this result.

pse.ServicesCreditsService.ManualAllocationResponse

global with sharing class ManualAllocationResponse

A structure containing the results of manuallyAllocateCreditsForMilestones

Properties

Name Type Description
results Map<Id, pse.ServicesCreditsService.ManualAllocationResult> A map of milestone ID to the manual allocation result for that milestone.

pse.ServicesCreditsService.ManualAllocationRequest

global with sharing class ManualAllocationRequest

A structure containing details needed to perform manual allocation for a milestone

Properties

Name Type Description
milestoneId Id The List of IDs of the milestones to allocate.
creditsToConsumeByPurchaseId Map<Id, Integer> A map of purchase ID to the number of credits to consume from that purchase

Methods

ManualAllocationRequest

global ManualAllocationRequest(Map<Id, Integer> creditsToConsumeByPurchaseId, Id milestoneId)

pse.ServicesCreditsService.ServicesCreditsAdjustmentRequest

global with sharing class ServicesCreditsAdjustmentRequest

A structure containing a map of milestone IDs to the number of credits to adjust to.

Properties

Name Type Description
newNumberOfCreditsByMilestoneId Map<Id, Integer> A map of milestone IDs to the number of credits to adjust to.

Methods

ServicesCreditsAdjustmentRequest

global ServicesCreditsAdjustmentRequest(Map<Id, Integer> newNumberOfCreditsByMilestoneId)

pse.ServicesCreditsService.ServicesCreditsAdjustmentResponse

global with sharing class ServicesCreditsAdjustmentResponse

This is currently an empty object which is reserved for future use.

pse.ServicesCreditsService.ManualAdjustmentRequest

global with sharing class ManualAdjustmentRequest

A structure containing details needed to perform manual adjustment for a milestone

Properties

Name Type Description
milestoneId Id The ID of the milestone to adjust.
changeInCreditsByPurchaseId Map<Id, Integer> A map of purchase ID to the number of credits to adjust that purchase by. Can be negative to return credits or positive to consume more credits.

Methods

ManualAdjustmentRequest

global ManualAdjustmentRequest(Map<Id, Integer> changeInCreditsByPurchaseId, Id milestoneId)

pse.ServicesCreditsService.ManualAdjustmentResponse

global with sharing class ManualAdjustmentResponse

A structure containing no data which is reserved for future use.

pse.ServicesCreditsService.ExpireCreditsForPurchaseResponse

global with sharing class ExpireCreditsForPurchaseResponse

A structure containing the response to expiring Services Credits Customer Purchases.

Properties

Name Type Description
resultsMap Map<Id, pse.ServicesCreditsService.ServicesCreditsExpiryResult> A map of the Services Credits Customer Purchase Id to its corresponding result.

pse.ServicesCreditsService.ServicesCreditsExpiryResult

global with sharing class ServicesCreditsExpiryResult

The result of the expiry for an individual Services Credits Customer Purchase.

Properties

Name Type Description
purchaseId Id The purchase Id the result relates to.
allocationId Id If successful the allocation that was created by the process.
errorMessage String If there was an error this will contain the error message.

Methods

hasError

global Boolean hasError()

Returns true if there was an error expiring this record.

pse.ServicesCreditsService.ExpireCreditsForPurchaseRequest

global with sharing class ExpireCreditsForPurchaseRequest

A structure containing the request to expire Services Credits Customer Purchases.

Properties

Name Type Description
purchaseIds List<Id> The List of IDs of the purchases to expire.

Methods

ExpireCreditsForPurchaseRequest

global ExpireCreditsForPurchaseRequest(List<Id> purchaseIds)

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