Download PDF
Download page Creating Direct Credit Memos.
Creating Direct Credit Memos
createDirectCreditMemos API is used to create credit memos for a list of invoices.
API | Signature |
---|---|
createDirectCreditMemos | static List createDirectCreditMemos(List creditMemoInputs) |
directCreditMemoResult createDirectCreditMemos(directCreditMemoInputs)
This API is used to create credit memos for an invoice. It accepts a Set of Account IDs, invoiceDate, and targetDateTime as input parameters. For each DirectCreditMemoInput, a credit memo is created in the Draft Status. You can auto-approve a credit memo line item and auto-apply it to an invoice. If you have a Tax Callback registered, this API also calculates Tax and creates Tax breakups for a credit memo line item.
Request - DirectCreditMemoInput | |||
---|---|---|---|
Field | Type | Required? | Description |
invoiceId | ID | Yes | The Id of the approved Invoice the credit will be drawn from. |
reasonCode | String | Yes | The reason for creating the Credit Memo. Must be null or a valid pick-list value for the Reason Code field declared of the Credit Memo object. |
isFullCredit | Boolean | No | If you set isFullCredit as true, the entire available credit amount of all the invoice line items is set as the credit amount. If you set the value as false, credit memo amount is calculated based on the values you provide in creditMemoLineItemInputs field. By default, it is set as false. |
creditMemoLineItemInputs | List<DirectCreditMemoLineItemInput> | No | The list of inputs for each Credit Memo Line Item to create. This parameter is ignored if you set isFullCredit as True. |
autoApprove | Boolean | No | If true the Credit Memo will be transitioned to Approved otherwise the Credit Memo will be created with a status of Draft. A value of null will be considered as false. |
autoApplyCreditMemo | Boolean | No | This flag is only relevant when the Auto Approve option is true. If both options are true the newly created direct Credit Memo will be applied to the Invoice, the credit was drawn from. A value of null will be considered as false. |
TemplateId | ID | No | The Id of the Credit Memo template to use when creating the Credit Memo attachment. This parameter is optional and can be null. |
calculateTax | Boolean | Yes | If this flag is true Tax will be calculated for a non tax-exempt Asset. If false, no tax will be calculated. |
Ensure that you provide value for either isFullCredit or creditMemoLineItemInputs parameters. If you leave both the fields as null, the API returns an error.
Request - CreditMemoLineItemInput | |||
---|---|---|---|
Field | Type | Required? | Description |
invoiceLineItemId | ID | Yes | The Id of the affiliate Invoice Line Item. It must be a child of the specified Invoice. |
creditAmount | Decimal | Yes | The amount of credit to draw from the corresponding Invoice Line Item. The amount must be a positive number and cannot exceed the available credit of the corresponding Invoice Line Item. |
Response | ||
---|---|---|
Field | Type | Description |
DirectCreditMemoResult | List | A result parameter is returned for each request parameter. |
Create Direct Credit Memo API returns an error if:
- The specified invoice does not exist.
- The status of your specified invoice is not Approved.
Your specified reason code is invalid. Reason code can be null or one of the picklist values declared in the Reason Code field of Credit Memo object.
Create Direct Credit Memo API does not support the following reason codes:
- Wallet Application
- Credit & Rebill
- Credit Amount is negative or 0.
- Template ID does not exist.
- Template Type is other than Credit Memo.
- Specified Invoice Line Item does not exist.
- Specified Invoice Line Item does not belong to the specified invoice.
- Invoice Line Item is already referenced in more than one Credit Memo Line Item.
- Credit Amount is greater than the Available Credit.
Code Sample 1
// Set Credit Memo input parameters
List<DirectCreditMemoInput> creditMemoInputs = new List<DirectCreditMemoInput>();
List<DirectCreditMemoInput.DirectCreditMemoLineItemInput> creditMemoLineItemInputs;
Set<Id> invoiceIds = new Set<Id>
{'a2V1N000002QbuC', 'a2V1N000002QbuM'}
;
List<Invoice__c> invoices = SELECT Id, Status__c, (Select Id, Amount__c From InvoiceLineItems__r) FROM Invoice__c Where Id IN:invoiceIds;
Id templateId = 'a1b1N000003QCS';
Decimal creditAmount = 100.00;
String reasonCode = null;
for(Invoice__c invoice : invoices){
creditMemoLineItemInputs = new List<DirectCreditMemoInput.DirectCreditMemoLineItemInput>();
for(InvoiceLineItem_c invoiceLineItem : invoice.InvoiceLineItems_r)
{ creditMemoLineItemInputs.add(new DirectCreditMemoInput.DirectCreditMemoLineItemInput(invoiceLineItem.Id, creditAmount)); }
creditMemoInputs.add(new DirectCreditMemoInput(invoice.Id,
reasonCode,
true,
true,
templateId,
true,
creditMemoLineItemInputs));
}
List<DirectCreditMemoResult> actualCreditMemoResults = Apttus_Billing.BillingService.createDirectCreditMemos(creditMemoInputs);
System.debug('actualCreditMemoResults========================'+actualCreditMemoResults);
Code Sample 2 - To provide Full Credit
Apttus_Billing.DirectCreditMemoInput dcm = new Apttus_Billing.DirectCreditMemoInput();
dcm.autoApplyCreditMemo = true;
dcm.autoApprove = true;
dcm.calculateTax = true;
dcm.creditMemoLineItemInputs = null;
dcm.invoiceId = 'a5F5x000001hqtJ';
dcm.isFullCredit = true;
dcm.reasonCode = 'Refund';
dcm.templateId = 'a03f200000lccG2';
List<Apttus_Billing.DirectCreditMemoInput> creditMemoInputs = new List<Apttus_Billing.DirectCreditMemoInput>();
creditMemoInputs.add(dcm);
List<Apttus_Billing.DirectCreditMemoResult> actualCreditMemoResults =
Apttus_Billing.BillingService.createDirectCreditMemos(creditMemoInputs);