Skip to content

API Reference


Master items are items that are not linked to a subscription. They represent products that are intended to be used as templates for subscription items.

The class ONBSE1.MasterItemRetriever can be used to retrieve all items that are configured as master items.

Method Description
global List<ONB2__Item__c> retrieve() This method runs a SOQL query on the database and returns a list of Items with their prices.
Only Items that have
ONB2__Active__c = true
ONB2__Subscription__c = null
and match the master item criteria are considered.
Prices are ordered by the value in their ONB2__Quantity__c field.
This method is independent of any session status, that is, a user is not required to be logged in.
Code Example: Retrieve all master items
ONBSE1.MasterItemRetriever retriever = new ONBSE1.MasterItemRetriever();
List<ONB2__Item__c> items = retriever.retrieve();

// Assuming there is at least one master item, you can get its associated prices with:
List<ONB2__Price__c> pricesOfFirstItem = items[0].ONB2__Prices__r;


If you have a list of master items that the user has selected, you can call the method checkout() of the class ONBSE1.SubscriptionManager. This clones the master items and adds them to a subscription – either a new one or the last active, depending on the configuration.

Method Description
global SubscriptionManager() The constructor.
global virtual Id checkout(List<ProductHolder> prodHolders) This method expects a list of ONBSE1.ProductHolder objects (see ProductHolder) as a parameter, which represent the contents of the shopping cart. The return value is the ID of a subscription record.

This method executes the following steps:

(1) Throw the exception SubscriptionSelfService.InvalidSessionException if the session handler reports "not authenticated".

(2) Return a null value if the parameter list is null or empty.

(3) Validate the ProductHolder list and throw the exception SubscriptionSelfService.InvalidItemException if a quantity is < 0 or an item ID does not belong to a master item.

(4) Get the account for the current session from the session handler and build a new subscription or retrieve the last active for this account from the database, depending on your configuration.

(5) Clone the master items; set the field ONB2__Quantity__c to each provided quantity and ONB2__Description__c to description.

(6) Insert/update the subscription and the new items.

(7) Return the ID of the subscription.


The ONBSE1.ProductHolder class represents the contents of the shopping cart.

Method/Field Description
global Id id This field holds a master item ID.
global Decimal quantity This field specifies the quantity of the master item.
global String description This field contains a description, which is copied to the field ONB2__Description__c of the cloned item.
global ProductHolder(Id id, Decimal quantity, String description) Constructor. The parameters are copied to the fields listed above.
Code Example: Checkout a master item

Checkout a master item with Id=masterItemId, quantity=5 and description="Foo" for a user who is currently logged in:

ONBSE1.SubscriptionManager manager = new ONBSE1.SubscriptionManager();

List<ONBSE1.ProductHolder> prodHolders = new List<ONBSE1.ProductHolder>{new ONBSE1.ProductHolder(masterItemId, 5, 'Foo')};

Id result = manager.checkout(prodHolders);


The ONBSE1.SubscriptionHolder is a wrapper class for the Subscription object.

Method/Field Description
global ONB2__Subscription__c subscription This field holds the Subscription sObject.
global Account account This field holds the associated account.
global List<ItemHolder> items This field holds the associated items.
global SubscriptionHolder() Constructor.
global SubscriptionHolder(ONB2__Subscription__c subscription, List<ItemHolder> items) Constructor.
global SubscriptionHolder subscription(ONB2__Subscription__c subscription) Setter for subscription.
global SubscriptionHolder account(Account account) Setter for account.
global SubscriptionHolder items(List<ItemHolder> items) Setter for items.
global Boolean first Is true if this is the first subscription in the list returned by the SubscriptionRetriever


The ONBSE1.ItemHolder is a wrapper class for the Item object.

Method/Field Description
global ONB2__Item__c item This field holds the Item sObject.
global List<ONB2__Price__c> prices This field holds a list of prices associated with the item.
global ONB2__Payment__c price The first price of all prices (sorted by Quantity__c)
global ONB2__Payment__c bestMatchingPrice The matching price according to its price tier.
global ItemHolder(ONB2__Item__c item) Constructor.
global ItemHolder duplicate() This method will make a clone of the ItemHolder. IDs are not cloned.


The ONBSE1.SubscriptionRetriever is a helper class for querying subscriptions.

Method Description
global SubscriptionRetriever(Id accountId) Constructor. Subscriptions will only be queried for the supplied account ID.
global SubscriptionHolder retrieve() Queries and returns the most recent Active subscription.
global List<SubscriptionHolder> retrieveAll(Integer n) Queries and returns the most recent n Active subscriptions.


The ONBSE1.InvoiceRetriever class is used to retrieve invoices for the account of the current session.

Method Description
public List<ONB2__Invoice__c> retrieve() Returns all non-draft invoices for the account of the current session. Queries all invoice fields and the related template fields. Returns an empty list if the current session is invalid.
Code Example
// create an InvoiceRetriever instance
ONBSE1.InvoiceRetriever retriever = new ONBSE1.InvoiceRetriever();

// query the database for invoices
List<ONB2__Invoice__c> invoices = retriever.retrieve();

// get the template of the first invoice (assuming the account of current session has a non-draft invoice)
ONB2__Template__c template = invoices[0].ONB2__Template__r;


The ONBSE1.DefaultSessionHandler is used to manage a user session. It logs in and logs out a user and returns account and contact.

Method Description
global static DefaultSessionHandler getInstance() Returns a singleton instance of DefaultSessionHandler.
global virtual Boolean isAuthenticated() Returns true if the user has a valid session.
global virtual Account getAccount() Returns the account of the current session.
global virtual Contact getContact() Returns the contact of the current session.
global virtual void login(Contact contact) Initializes a session for contact and sets the sessionId cookie.
global virtual void logout() Invalidates the current session and clears the sessionId cookie.