Professional Services Automation Apex API Developer Reference

pse.VersionConfigService

global with sharing class VersionConfigService

Service to create, modify and validate custom configurations for Project Versioning and Baselines.

Methods

deleteVersionConfigDetails

global static void deleteVersionConfigDetails(List<Id> configIds)

This method deletes the Version_Config__c objects with the list of IDs as passed in.

Input Parameters

Name Type Description
configIds List<Id> List of IDs to be deleted.

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.

// return all the capture configuration sets on the org, we assume here that we get five back
pse.VersionConfigService.VersionConfigDetails[] details = pse.VersionConfigService.getAllVersionConfigDetails();

List<Id> configsToDelete = new List<Id>();
configsToDelete.add(details[1].ConfigId);
configsToDelete.add(details[3].ConfigId);

pse.VersionConfigService.deleteVersionConfigDetails(configsToDelete);

getActiveVersionConfig

global static pse__Version_Config__c getActiveVersionConfig()

This method returns the active Version_Config__c object, or the standard Version_Config__c object if there is not an active custom config.

Return Value

The active Version_Config__c 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.

pse__Version_Config__c activeConfig = pse.VersionConfigService.getActiveVersionConfig();

getAllVersionConfigDetails

global static pse.VersionConfigService.VersionConfigDetails[] getAllVersionConfigDetails()

This method loads the ID, Unique_Name__c, Default__c, Summary__c and LastModifiedDate fields on all Version_Config__c objects

Return Value

List of Version_Config__c records.

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.

// return all the capture configuration sets on the org, we assume here that we get three back
pse.VersionConfigService.VersionConfigDetails[] details = pse.VersionConfigService.getAllVersionConfigDetails();

Integer i = 1;

for (pse.VersionConfigService.VersionConfigDetails detail : details)
{
    detail.Name = detail.Name + i;

    if (i == 3)
        detail.isDefault = true;

    i++;
}

// save all the capture configurations back to the org
pse.VersionConfigService.VersionConfigDetails[] updated = pse.VersionConfigService.saveVersionConfigDetails(details);

getConfigById

global static pse__Version_Config__c getConfigById(Id configId)

This method returns the Version_Config__c object with the ID as passed in.

Input Parameters

Name Type Description
configId Id The ID of the Version_Config__c object to return.

Return Value

The Version_Config__c object with the given ID.

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 configId = Id.valueOf('a3j1a0000008uAP'); // assume that we already have the Id from elsewhere.

pse__Version_Config__c fullConfig = VersionConfigService.getConfigById(configId);

getVersionCaptureConfigById

global static pse.VersionConfigService.VersionCaptureConfig getVersionCaptureConfigById(Id configId)

This method returns the VersionCaptureConfig object with the ID as passed in.

Input Parameters

Name Type Description
configId Id The ID of the VersionCaptureConfig object to return.

Return Value

The VersionCaptureConfig object with the given ID.

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 configId = Id.valueOf('a3j1a0000008uAP'); // assume that we already have the Id from elsewhere.

pse.VersionConfigService.VersionCaptureConfig fullConfig = VersionConfigService.getVersionCaptureConfigById(configId);

saveCaptureConfig

global static pse.VersionConfigService.VersionCaptureConfig saveCaptureConfig(Id configId, pse.VersionConfigService.VersionCaptureConfig toSave)

This method saves the given VersionCaptureConfig to the Version_Config__c object with the given ID.

Input Parameters

Name Type Description
configId Id ID of Version_Config__c objects to be saved.
toSave pse.VersionConfigService.VersionCaptureConfig VersionCaptureConfig object to be saved to the Version_Config__c.

Return Value

The saved VersionConfigService.VersionCaptureConfig.

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 configId = Id.valueOf('a3j1a0000008uAK'); // A valid pse__Version_Config__c record

pse.VersionConfigService.VersionCaptureConfig captureConfig = new pse.VersionConfigService.VersionCaptureConfig();

// configure to capture the Project object
pse.VersionConfigService.VersionCaptureObject projectConfig = new pse.VersionConfigService.VersionCaptureObject();
projectConfig.originatorAPIName = 'pse__Proj__c';
projectConfig.originatorProjectLookupFieldAPIName = '';
projectConfig.destinationAPIName = 'pse__VersionItem_ProjectDetail__c';
projectConfig.destinationVersionLookupFieldAPIName = 'pse__Version__c';
projectConfig.originalIdField = 'pse__OriginalId__c';

captureConfig.VersionedObjects.add(projectConfig);

// add the Project Task object to the capture configuration
pse.VersionConfigService.VersionCaptureObject taskConfig = new pse.VersionConfigService.VersionCaptureObject();
taskConfig.originatorAPIName = 'pse__Project_Task__c';
taskConfig.originatorProjectLookupFieldAPIName = 'pse__Project__c';
taskConfig.destinationAPIName = 'pse__VersionItem_Task__c';
taskConfig.destinationVersionLookupFieldAPIName = 'pse__Version__c';
taskConfig.originalIdField = 'pse__OriginalId__c';

captureConfig.VersionedObjects.add(taskConfig);

// add a custom object to the configuration
pse.VersionConfigService.VersionCaptureObject myObjectConfig = new pse.VersionConfigService.VersionCaptureObject();
// orgNs is the namespace of the org, if appropriate
myObjectConfig.originatorAPIName = 'orgNs__MyObject__c';
// custom objects have to have a lookup to Project to be versionable
myObjectConfig.originatorProjectLookupFieldAPIName = 'orgNs__Prj__c';
// the destination object for custom objects will need to be created by an administrator
myObjectConfig.destinationAPIName = 'orgNs__My_Destination_Object__c';
// and will need to have a lookup to the pse__Version__c object
myObjectConfig.destinationVersionLookupFieldAPIName = 'orgNs__Vrsn__c';
// and have a field for capturing the Id of the originator object
myObjectConfig.originalIdField = 'orgNs__My_Object_Id__c';

captureConfig.VersionedObjects.add(myObjectConfig);

captureConfig = pse.VersionConfigService.saveCaptureConfig(configId, captureConfig);

saveVersionConfigDetails

global static pse.VersionConfigService.VersionConfigDetails[] saveVersionConfigDetails(List<pse.VersionConfigService.VersionConfigDetails> details)

This method saves the given list of VersionConfigDetails to their equivalent Version_Config__c objects.

Input Parameters

Name Type Description
details List<pse.VersionConfigService.VersionConfigDetails> List of VersionConfigDetails to be saved.

Return Value

Updated VersionConfigService.VersionConfigDetails records.

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.

// return all the capture configuration sets on the org, we assume here that we get three back
pse.VersionConfigService.VersionConfigDetails[] details = pse.VersionConfigService.getAllVersionConfigDetails();

Integer i = 1;

for (pse.VersionConfigService.VersionConfigDetails detail : details)
{
    detail.Name = detail.Name + i;

    if (i == 3)
        detail.isDefault = true;

    i++;
}

// save all the capture configurations back to the org
pse.VersionConfigService.VersionConfigDetails[] updated = pse.VersionConfigService.saveVersionConfigDetails(details);

validateCaptureConfig

global static pse.VersionConfigService.ValidationResult[] validateCaptureConfig(Id[] configIds)

This method retrieves the Version_Config__c records with the given IDs and validates the VersionCaptureConfigs contained within.

Input Parameters

Name Type Description
configIds Id[] List of IDs of the VersionCaptureConfig objects to validate.

Return Value

Returns a list of validation results. One result per ID is returned in the order as given.

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__Version_Config__c newConfig = pse.VersionConfigService.getCloneOfPSAPackagedDefault();
newConfig.pse__Unique_Name__c = 'My copy of default config';
insert newConfig;

pse__Version_Config__c existingConfig = [SELECT Id FROM pse__Version_Config__c WHERE pse__Unique_Name__c = 'Time and material config'];

List<Id> configIdsToValidate = new List<Id>();
configIdsToValidate.add(newConfig.Id);
configIdsToValidate.add(existingConfig.Id);
configIdsToValidate.add('a3ff400000066RUAAY');

pse.VersionConfigService.ValidationResult[] results = pse.VersionConfigService.validateCaptureConfig(configIdsToValidate);

for(pse.VersionConfigService.ValidationResult result : results)
{
    if(result.HasFailed)
    {
        for (pse.VersionConfigService.ValidationRecordWrapper wrapper : result.FailedRecords)
        {
            // What went wrong?
            System.debug(wrapper.ErrorMessage);
            // With what part?
            System.debug(wrapper.OriginatorLabel + ' ' + wrapper.DestinationLabel + ' ' + wrapper.FieldLabel);
        }
    }
}

validateCaptureConfig

global static pse.VersionConfigService.ValidationResult[] validateCaptureConfig(pse.VersionConfigService.VersionCaptureConfig[] captureConfigs)

This method validates the given VersionCaptureConfig objects.

Input Parameters

Name Type Description
captureConfigs pse.VersionConfigService.VersionCaptureConfig[] VersionCaptureConfigs to validate.

Return Value

Returns a list of validation results. One result per ID is returned in the order as passed.

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__Version_Config__c newConfig = pse.VersionConfigService.getCloneOfPSAPackagedDefault();
newConfig.pse__Unique_Name__c = 'My copy of default config';

pse__Version_Config__c existingConfig = [SELECT Id, pse__Capture_Config__c FROM pse__Version_Config__c WHERE pse__Unique_Name__c = 'Time and material config'];

List<pse.VersionConfigService.VersionCaptureConfig> configsToValidate = new List<pse.VersionConfigService.VersionCaptureConfig>();
pse.VersionConfigService.VersionCaptureConfig newCaptureConfigDTO = (pse.VersionConfigService.VersionCaptureConfig) JSON.deserialize(newConfig.pse__Capture_Config__c, pse.VersionConfigService.VersionCaptureConfig.class);
pse.VersionConfigService.VersionCaptureConfig existingCaptureConfigDTO = (pse.VersionConfigService.VersionCaptureConfig) JSON.deserialize(existingConfig.pse__Capture_Config__c, pse.VersionConfigService.VersionCaptureConfig.class);

configsToValidate.add(newCaptureConfigDTO);
configsToValidate.add(existingCaptureConfigDTO);

pse.VersionConfigService.ValidationResult[] results = pse.VersionConfigService.validateCaptureConfig(configsToValidate);

for(pse.VersionConfigService.ValidationResult result : results)
{
    if(result.HasFailed)
    {
        for (pse.VersionConfigService.ValidationRecordWrapper wrapper : result.FailedRecords)
        {
            // What went wrong?
            System.debug(wrapper.ErrorMessage);
            // With what part?
            System.debug(wrapper.OriginatorLabel + ' ' + wrapper.DestinationLabel + ' ' + wrapper.FieldLabel);
        }
    }
}

pse.VersionConfigService.VersionConfigDetails

global inherited sharing class VersionConfigDetails

Lightweight DTO for the details of the Version_Config__c object excluding the Capture_Config__c field. Used for quickly saving changes to the object such as Unique_Name__c and Default__c

Properties

Name Type Description
ConfigId Id The Salesforce ID of the Version_Config__c record represented by this DTO.
Name String The unique name of the Version_Config__c.
Summary String A description of the configuration.
IsDefault Boolean A flag to indicate whether this configuration is the one used when creating baselines and versions of not.
LastModifiedDate Datetime The Salesforce timestamp showing when the record was last changed.

Methods

VersionConfigDetails

global VersionConfigDetails()

pse.VersionConfigService.VersionCaptureConfig

global inherited sharing class VersionCaptureConfig

A representation of the whole capture configuration.
The capture configuration is stored on the pse__Version_Config__c.Capture_Config__c field in JSON format.

Properties

Name Type Description
VersionedObjects pse.VersionConfigService.VersionCaptureObject[] An array of all the objects you want to version as part of the configuration.

Methods

VersionCaptureConfig

global VersionCaptureConfig()

pse.VersionConfigService.VersionCaptureObject

global inherited sharing class VersionCaptureObject

A representation of an object you want to version.

Properties

Name Type Description
VersionedFields pse.VersionConfigService.VersionCaptureField[] An array of fields you want to version.
OriginalIdField String The API name of the field on the destination object that holds the ID of the original object.
OriginatorAPIName String The API name of the SObject you are versioning.
OriginatorProjectLookupFieldAPIName String The API name of the field on the original object that is the relationship used to link to the project you are versioning.
DestinationAPIName String The API name of the destination SObject that holds the content from the original record used to generate a version.
DestinationVersionLookupFieldAPIName String The API name of the field with a relationship to the master Version__c record. This field relationship can be a lookup or master detail.

Methods

VersionCaptureObject

global VersionCaptureObject()

pse.VersionConfigService.VersionCaptureField

global inherited sharing class VersionCaptureField

A representation of the field you want to capture.

Properties

Name Type Description
OriginatorFieldAPIName String The API name of the field you want to capture from.
DestinationFieldAPIName String The API name of the field on the destination record to hold the copied value from the original record.

Methods

VersionCaptureField

global VersionCaptureField()

pse.VersionConfigService.ValidationResult

global inherited sharing class ValidationResult

An instance of this object contains the results of a validation.
Users can quickly check if the validation passed with the HasFailed property then if a failure has occured check the FailedRecords list.

Properties

Name Type Description
FailedRecords List<pse.VersionConfigService.ValidationFailure> A list of failed records. Depending when the validation failed the list can contain a wrapped record for the config, one or more objects, or one or more fields. The list is empty when there are no failures.
HasFailed Boolean An indication that the validation failed. If true, the FailedRecords list contains one or more items.

Methods

ValidationResult

global ValidationResult()

pse.VersionConfigService.ValidationFailure

global inherited sharing class ValidationFailure

An object denoting a failure in the VersionConfigValidator, to be created from a ValidationResultWrapper.
Encapsulates any failures and the reasons for the failure.

Properties

Name Type Description
ErrorMessage String The error that caused the validation failure.
OriginatorName String The API name of the originator object which failed validation.
OriginatorLabel String The label of the originator object which failed validation.
DestinationName String The API name of the destination object which failed validation.
DestinationLabel String The label of the destination object which failed validation.
FieldName String The API name of the field which failed validation.
FieldLabel String The label of the field which failed validation.

Methods

ValidationFailure

global ValidationFailure()

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