You can add new lines, edit or delete existing lines to an invoice by calling the API Apttus_Billing.BillingService.manageAdHocLines.

The API can handle only one operation (Add, Edit, or Delete) at a time.

You must provide the following information:

  • Enter the start date in (YYYY, MM, DD) format. The start date cannot be left blank and must be in the range of the start date and end date of the system-generated invoice line item(s).
  • Enter the end date in (YYYY, MM, DD) format. The end date cannot be left blank and must be in the range of the start date and end date of the system-generated invoice line item(s).
  • Enter a description (e.g., "Miscellaneous charges", "Additional installation charges", etc.) for the ad hoc invoice line item entry.
  • Enter the fee amount to be charged in the Amount field. Decimal places cannot be greater than the value supplied in the setting Billing System Properties > Currency Decimal Places.

If you have entered multiple inputs to add line items, and even if there is a validation error for one of the inputs, other inputs are not processed.

The API snippets to add, edit, or delete operations are given in the table:

Add New Line

List<Apttus_Billing.CustomClass.AdHocLineItemInput> inputs = new List<Apttus_Billing.CustomClass.AdHocLineItemInput>();
 
// Prepare adhoc line items for first invoice 
List<Apttus_Billing__InvoiceLineItem__c> invoiceLineItems = new List<Apttus_Billing__InvoiceLineItem__c>();
Apttus_Billing__InvoiceLineItem__c invoiceLineItem = new Apttus_Billing__InvoiceLineItem__c();
 
invoiceLineItem.Apttus_Billing__StartDate__c = Date.newInstance(2024, 3, 6);
invoiceLineItem.Apttus_Billing__EndDate__c = Date.newInstance(2024, 3, 30);
invoiceLineItem.Apttus_Billing__Description__c = 'Additional Installation Charges';
invoiceLineItem.Apttus_Billing__Amount__c = 52;
// Add any other invoice line item fields if required
invoiceLineItems.add(invoiceLineItem);
 
 
Apttus_Billing.CustomClass.AdHocLineItemInput input1 = new Apttus_Billing.CustomClass.AdHocLineItemInput('a5T040000000oQF', invoiceLineItems);
inputs.add(input1);
 
// First parameter of the API can be "Add", "Edit" or "Delete"
List<Apttus_Billing.CustomClass.AdHocLineItemResult> results = Apttus_Billing.BillingService.manageAdHocLines('Add', inputs);
System.debug('====='+results);
CODE

When you call this API, it adds a new line to the system-generated or ad hoc invoices.

You must provide:

  • Start date in (YYYY, MM, DD) format.
  • End date in (YYYY, MM, DD) format.
  • Description as plain text.
  • Currency value in the Amount field.

You can provide any of the standard or custom fields listed under the Custom Fields & Relationships of Invoice Line Item object, in the input section.

The invoiceLineItem.Id field must be blank for a new line addition.

After the execution is complete, you are returned to the invoice record where you can see the invoice line item(s) is(are) created under the invoice line item(s) related list but the "Type" field will have a value "Additional Fee" thus differentiating them from the system generated invoice lines.

Edit an Existing Line

List<Apttus_Billing.CustomClass.AdHocLineItemInput> inputs = new List<Apttus_Billing.CustomClass.AdHocLineItemInput>();
 
// Prepare adhoc line items for first invoice 
List<Apttus_Billing__InvoiceLineItem__c> invoiceLineItems = new List<Apttus_Billing__InvoiceLineItem__c>();
Apttus_Billing__InvoiceLineItem__c invoiceLineItem = new Apttus_Billing__InvoiceLineItem__c();
 
invoiceLineItem.Apttus_Billing__StartDate__c = Date.newInstance(2024, 11, 3);
invoiceLineItem.Apttus_Billing__EndDate__c = Date.newInstance(2024, 11, 30);
invoiceLineItem.Apttus_Billing__Description__c = 'Misc Charges';
invoiceLineItem.Apttus_Billing__Amount__c = 102;
invoiceLineItem.Id = 'a2X3m000002HpY9'; // Invoice Line Item Id should be provided for "Edit" and "Delete"
// Add any other invoice line item fields if required
invoiceLineItems.add(invoiceLineItem);
 
 
Apttus_Billing.CustomClass.AdHocLineItemInput input1 = new Apttus_Billing.CustomClass.AdHocLineItemInput('a5T040000000oQF', invoiceLineItems);
inputs.add(input1);
 
// First parameter of the API can be "Add", "Edit" or "Delete"
List<Apttus_Billing.CustomClass.AdHocLineItemResult> results = Apttus_Billing.BillingService.manageAdHocLines('Edit', inputs);
System.debug('====='+results);
CODE

When you call this API, it edits the data of an existing line that is added to the system-generated or ad hoc invoice.

You must provide the ID of the existing line that is added to the system-generated or ad hoc invoices in the invoiceLineItem.Id field to execute the Edit operation.

The invoiceLineItem.Id field must not be blank. It must contain the ID of the invoice line to be edited.

You can edit every data including:

  • Start date
  • End date
  • Description
  • Currency value in the Amount field.

After the execution is complete, you are returned to the invoice record page where you can see your changes on the invoice record.


Delete an Existing Line

List<Apttus_Billing.CustomClass.AdHocLineItemInput> inputs = new List<Apttus_Billing.CustomClass.AdHocLineItemInput>();
 
// Prepare adhoc line items for first invoice 
List<Apttus_Billing__InvoiceLineItem__c> invoiceLineItems = new List<Apttus_Billing__InvoiceLineItem__c>();
Apttus_Billing__InvoiceLineItem__c invoiceLineItem = new Apttus_Billing__InvoiceLineItem__c();
 
invoiceLineItem.Id = 'a5P04000000dSUy'; // Invoice Line Item Id should be provided for "Edit" and "Delete"
invoiceLineItems.add(invoiceLineItem);
 
 
Apttus_Billing.CustomClass.AdHocLineItemInput input1 = new Apttus_Billing.CustomClass.AdHocLineItemInput('a5T040000000oQF', invoiceLineItems);
inputs.add(input1);
 
// First parameter of the API can be "Add", "Edit" or "Delete"
List<Apttus_Billing.CustomClass.AdHocLineItemResult> results = Apttus_Billing.BillingService.manageAdHocLines('delete', inputs);
System.debug('====='+results);
CODE

When you call this API, it deletes an existing line that is added to the system-generated or ad hoc invoice.

You must provide:

  • The ID of the invoice line item to be deleted.

The invoiceLineItem.Id field must not be blank. It must contain the ID of the invoice line to be deleted.

After the execution is complete, you are returned to the invoice record page where you can see the "Record Deleted" message.