Billing Central Apex API Developer Reference

ffbc.OpportunityToContractPlugin

global with sharing class OpportunityToContractPlugin

Contains the plugin interface for the opportunity to contract conversion process.

ffbc.OpportunityToContractPlugin.AbstractPlugin

global inherited sharing abstract class AbstractPlugin implements IPlugin

The abstract base class of plugins for the opportunity to contract conversion process. Extend this class to create a custom plugin that can be invoked from the conversion process. The extension should be global to be visible to Billing Central. Specify the Apex class name and name space in the BC Opportunity to Contract Settings custom setting.

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.

/**
 * An implementation of ffbc.OpportunityToContractPlugin.AbstractPlugin to be invoked when an opportunity is converted into a contract through an update operation
 * or by calling ffbc.OpportunityToContractService.convert.
 * The name and namespace of the class must be specified in Billing Central Plugin Settings.
 */
global with sharing class OpportunityToContractCustomPlugin extends ffbc.OpportunityToContractPlugin.AbstractPlugin
{
    private final Id newProductId;

    global OpportunityToContractCustomPlugin()
    {
        // The no-arg constructor will be invoked
        this.newProductId = [SELECT Id FROM Product2 WHERE Name = 'Add-on'].Id;
    }

    global override void convert(ffbc.OpportunityToContractPlugin.Conversion conversion)
    {
        List<ffbc.OpportunityToContractPlugin.NewContract> newContracts = conversion.getNewContracts();
        List<ffbc.OpportunityToContractPlugin.ReplacementContract> replacementContracts = conversion.getReplacementContracts();
        List<ffbc.OpportunityToContractPlugin.RenewalContract> renewalContracts = conversion.getRenewalContracts();

        // The contracts of each conversion type can be handled separately.

        for (ffbc.OpportunityToContractPlugin.NewContract newContract : newContracts)
        {
            List<ffbc.OpportunityToContractPlugin.NewContractLineItem> lines = newContract.getLines();
            convertContract(newContract, lines);
        }

        for (ffbc.OpportunityToContractPlugin.ReplacementContract replacement : replacementContracts)
        {
            List<ffbc.OpportunityToContractPlugin.ReplacementContractLineItem> lines = replacement.getLines();
            convertContract(replacement, lines);
        }

        for (ffbc.OpportunityToContractPlugin.RenewalContract renewal : renewalContracts)
        {
            List<ffbc.OpportunityToContractPlugin.RenewalContractLineItem> lines = renewal.getLines();
            convertContract(renewal, lines);
        }
    }

    private void convertContract(ffbc.OpportunityToContractPlugin.DraftContract contract, List<ffbc.OpportunityToContractPlugin.ContractLineItem> lines)
    {
        // Each contract object extends a common base class, ffbc.OpportunityToContractPlugin.Contract, so we can apply common logic to them.
        addNewLines(contract);
        updateOpportunity(contract.getOpportunity());
        updateContract(contract.getContract());
        updateLines(lines);
        removeLines(lines);
    }

    private void addNewLines(ffbc.OpportunityToContractPlugin.Contract contract)
    {
        // New lines added in this way must be valid for the contract.
        ffbc__ContractLineItem__c line1 = new ffbc__ContractLineItem__c(
            ffbc__UnitPrice__c = 10.00,
            ffbc__Quantity__c = 5,
            ffbc__ProductService__c = newProductId,
            ffbc__Description__c = 'Add-on line 1'
        );

        ffbc__ContractLineItem__c line2 = new ffbc__ContractLineItem__c(
            ffbc__UnitPrice__c = 12.99,
            ffbc__Quantity__c = 10,
            ffbc__ProductService__c = newProductId,
            ffbc__Description__c = 'Add-on line 2'
        );

        List<ffbc__ContractLineItem__c> lines = new List<ffbc__ContractLineItem__c>{line1, line2};
        // When the changes are committed, these lines will be inserted into the database.
        contract.addNewLines(lines);
    }

    private void updateOpportunity(Opportunity opp)
    {
        // Any fields that could usually be updated on an opportunity can be modified.
        opp.Description = 'Add-ons included';
    }

    private void updateContract(ffbc__Contract__c contract)
    {
        // Any fields that could usually be set on a new contract can be modified.
        contract.ffbc__Description__c = 'Add-ons will be billed.';
    }

    private void updateLines(List<ffbc.OpportunityToContractPlugin.ContractLineItem> lines)
    {
        for (ffbc.OpportunityToContractPlugin.ContractLineItem line : lines)
        {
            OpportunityLineItem oppLine = line.getOpportunityLineItem();
            ffbc__ContractLineItem__c contractLine = line.getContractLineItem();

            // Some fields on the opportunity and opportunity line item may not be retrieved by SOQL, so check before reading the fields.
            if (oppLine.getPopulatedFieldsAsMap().containsKey('Description'))
            {
                // Any fields that could usually be set on a new contract line item can be modified.
                // To directly copy field values from the opportunity to contract or opportunity line item to contract line item, use ffbc Field Mappings instead.
                // The specified field mappings are carried out at the time when the plugin is invoked.
                contractLine.ffbc__Description__c = oppLine.Description.substring(0, 255);
            }

            if (oppLine.getPopulatedFieldsAsMap().containsKey('Quantity'))
            {
                contractLine.ffbc__Quantity__c = oppLine.Quantity * 2;
            }
        }
    }

    private void removeLines(List<ffbc.OpportunityToContractPlugin.ContractLineItem> lines)
    {
        for (ffbc.OpportunityToContractPlugin.ContractLineItem line : lines)
        {
            ffbc__ContractLineItem__c contractLine = line.getContractLineItem();
            if (contractLine.ffbc__EndDate__c < Date.today())
            {
                // Remove the line from the contract. When the changes are committed, this line will not be inserted into the database.
                line.remove();
            }
        }
    }
}

Methods

convert

global abstract void convert(ffbc.OpportunityToContractPlugin.Conversion conversion)

This method is called once after contracts and contract line items have been converted from opportunities, and before the changes to those objects are committed to the database. If the process has been initiated by an update to multiple opportunities, this method will be called once for each chunk that is processed by the opportunity trigger. Modifications to the supplied SObjects will be committed to the database. SObjects can be added to or removed from the resulting commit by calling the appropriate methods on the supplied objects.

Input Parameters

Name Type Description
conversion ffbc.OpportunityToContractPlugin.Conversion The results of the opportunity to contract conversion process.

ffbc.OpportunityToContractPlugin.Contract

global with sharing abstract class Contract

A contract that was converted from an opportunity.

Methods

getOpportunity

global abstract Opportunity getOpportunity()

The opportunity from which the contract was converted. Modifications to this object will be committed to the database. This object is retrieved via SOQL, so some fields may not be available. Use the getPopulatedFieldsAsMap method on SObject to determine whether fields are retrieved.

Return Value

The opportunity from which the contract was converted.

addNewLines

global abstract void addNewLines(List<ffbc__ContractLineItem__c> lines)

Adds new contract line items to the contract. Lines added in this way cannot be removed.

Input Parameters

Name Type Description
lines List<ffbc__ContractLineItem__c> The new contract line items to add. Required. Contract line items added in this way will be committed to the database. These objects should not already exist on the database.

Exceptions Thrown

Value Description
BillingCentralException An exception is thrown if the list of lines is null or if any of the lines are null.

ffbc.OpportunityToContractPlugin.ContractLineItem

global with sharing abstract class ContractLineItem

A contract line item that was converted from an opportunity line item.

Methods

getOpportunityLineItem

global abstract OpportunityLineItem getOpportunityLineItem()

The opportunity line item from which the contract line item was converted. This SObject should be treated as read only. Modifications to this object will not be committed to the database. This object is retrieved via SOQL, so some fields may not be available. Use the getPopulatedFieldsAsMap method on SObject to determine whether fields are retrieved.

Return Value

The opportunity line item from which the contract line item was converted.

getContractLineItem

global abstract ffbc__ContractLineItem__c getContractLineItem()

The contract line item that was converted from the opportunity line item. Modifications to this object will be committed to the database. This object is a new contract line item that does not exist on the database.

Return Value

The contract line item that was converted from the opportunity line item.

remove

global abstract void remove()

Remove the contract line item from the contract. Contract line items removed in this way will not be committed to the database.

ffbc.OpportunityToContractPlugin.Conversion

global with sharing abstract class Conversion

Contains the results of an opportunity to contract conversion process.

Methods

getNewContracts

global abstract List<ffbc.OpportunityToContractPlugin.NewContract> getNewContracts()

The list of newly created contracts which were converted from Opportunities. Adding or removing elements in this list will not affect the records that are committed to the database.

Return Value

The list of newly created contracts.

getReplacementContracts

global abstract List<ffbc.OpportunityToContractPlugin.ReplacementContract> getReplacementContracts()

The list of replacement contracts which were converted from Opportunities. Adding or removing elements in this list will not affect the records that are committed to the database.

Return Value

The list of replacement contracts.

getRenewalContracts

global abstract List<ffbc.OpportunityToContractPlugin.RenewalContract> getRenewalContracts()

The list of renewal contracts which were converted from Opportunities. Adding or removing elements in this list will not affect the records that are committed to the database.

Return Value

The list of renewal contracts.

getUpsellContracts

global abstract List<ffbc.OpportunityToContractPlugin.UpsellContract> getUpsellContracts()

The list of upsell contracts which were converted from Opportunities. Adding or removing elements in this list will not affect the records that are committed to the database.

Return Value

The list of upsell contracts.

ffbc.OpportunityToContractPlugin.DraftContract

global with sharing abstract class DraftContract extends Contract

A draft contract that was converted from an opportunity.

This class extends ffbc.OpportunityToContractPlugin.Contract

Methods

getContract

global abstract ffbc__Contract__c getContract()

The contract that was converted from the opportunity. Modifications to this object will be committed to the database. This object is a new contract that does not exist on the database.

Return Value

The contract that was converted from the opportunity.

ffbc.OpportunityToContractPlugin.NewContract

global with sharing abstract class NewContract extends DraftContract

A newly created contract that was converted from an opportunity.

This class extends ffbc.OpportunityToContractPlugin.DraftContract

Methods

getLines

global abstract List<ffbc.OpportunityToContractPlugin.NewContractLineItem> getLines()

The list of contract line items that were converted from the opportunity. Adding or removing elements in this list will not affect the records that are committed to the database. To add contract line items to the contract, use the addNewLines method. To remove contract line items from the contract, call the remove method on the line. This list will not be affected by calling those methods.

Return Value

The list of contract line items that were converted from the opportunity.

ffbc.OpportunityToContractPlugin.NewContractLineItem

global with sharing abstract class NewContractLineItem extends ContractLineItem

A contract line item that belongs to a newly created contract.

This class extends ffbc.OpportunityToContractPlugin.ContractLineItem

ffbc.OpportunityToContractPlugin.RenewalContract

global with sharing abstract class RenewalContract extends DraftContract

A renewal contract that was converted from an opportunity.

This class extends ffbc.OpportunityToContractPlugin.DraftContract

Methods

getLines

global abstract List<ffbc.OpportunityToContractPlugin.RenewalContractLineItem> getLines()

The list of contract line items that were converted from the opportunity. Adding or removing elements in this list will not affect the records that are committed to the database. To add contract line items to the contract, use the addNewLines method. To remove contract line items from the contract, call the remove method on the line. This list will not be affected by calling those methods.

Return Value

The list of contract line items that were converted from the opportunity.

ffbc.OpportunityToContractPlugin.RenewalContractLineItem

global with sharing abstract class RenewalContractLineItem extends ContractLineItem

A contract line item that belongs to a renewal contract.

This class extends ffbc.OpportunityToContractPlugin.ContractLineItem

ffbc.OpportunityToContractPlugin.ReplacementContract

global with sharing abstract class ReplacementContract extends DraftContract

A replacement contract that was converted from an opportunity.

This class extends ffbc.OpportunityToContractPlugin.DraftContract

Methods

getLines

global abstract List<ffbc.OpportunityToContractPlugin.ReplacementContractLineItem> getLines()

The list of contract line items that were converted from the opportunity. Adding or removing elements in this list will not affect the records that are committed to the database. To add contract line items to the contract, use the addNewLines method. To remove contract line items from the contract, call the remove method on the line. This list will not be affected by calling those methods.

Return Value

The list of contract line items that were converted from the opportunity.

ffbc.OpportunityToContractPlugin.ReplacementContractLineItem

global with sharing abstract class ReplacementContractLineItem extends ContractLineItem

A contract line item that belongs to a replacement contract.

This class extends ffbc.OpportunityToContractPlugin.ContractLineItem

ffbc.OpportunityToContractPlugin.UpsellContract

global with sharing abstract class UpsellContract extends Contract

A contract that was upsold by an opportunity. Plugin implementations should not update the original active contract or its lines as this may affect data integrity.

This class extends ffbc.OpportunityToContractPlugin.Contract

Methods

getOriginalContract

global abstract ffbc__Contract__c getOriginalContract()

The original active contract that was upsold by the opportunity. This object should be treated as read only, and modifications will not be committed to the database. This object is an existing contract that exists on the database. This object is retrieved via SOQL, so some fields may not be available. Use the getPopulatedFieldsAsMap method on SObject to determine whether fields are retrieved.

Return Value

The original active contract of the upsell.

getLines

global abstract List<ffbc.OpportunityToContractPlugin.UpsellContractLineItem> getLines()

The list of contract line items that were converted from the opportunity. Adding or removing elements in this list will not affect the records that are committed to the database. To add contract line items to the contract, use the addNewLines method. To remove contract line items from the contract, call the remove method on the line. This list will not be affected by calling those methods.

Return Value

The list of contract line items that were converted from the opportunity.

ffbc.OpportunityToContractPlugin.UpsellContractLineItem

global with sharing abstract class UpsellContractLineItem extends ContractLineItem

A contract line item that belongs to an upsell contract.

This class extends ffbc.OpportunityToContractPlugin.ContractLineItem

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