Overview
The following provides information regarding insertion and posting and un-posting API calls for the Journal Entry Object:
- Object API Names
- Required Fields
- Post & Unpost Global Class
Field Name | API Name | Type |
Journal Entry Name | Name | Text(80) |
Field Name | API Name | Type |
Journal Entry |
AcctSeed_Journal_Entry__c | Master Detail (Journal Entry) |
Debit/Credit | AcctSeed__Debit__c AcctSeed__Credit__c |
Currency(16,2) Either a debit or credit is required. |
GL Account | AcctSeed__GLAccount__c | Lookup (GL Account) |
Post & Unpost Global Class
There is a global class in the called JournalEntryPostService. This class contains two static global methods. One is related to posting journal entry records called postJournalEntries and another is related to un-posting journal entry records called unpostJournalEntries.
You cannot call either method with more than 1,000 journal entry lines. If you need to post or un-post more than 1,000 journal entry lines you will need to call the class static method from a class which implements the Apex batchable interface.
Each method returns a list of post-result records which will indicate if the journal entry was posted or un-posted successfully. If the record was not posted or un-posted successfully, an error code is provided, documenting the reason the record was not posted or un-posted.
The following error codes are supported for journal entry service:
-
LINE_COUNT_LIMIT_EXCEEDED - attempted to post a set of journal entry records where the aggregate number of lines exceeded 1000.
-
NO_LINES – the journal entry record does not have any associated journal entry lines and cannot be posted.
-
CLOSED_ACCOUNTING_PERIOD - accounting period associated with the journal entry is closed.
-
ALREADY_POSTED - record is already posted you are attempting to post
-
STATUS_NOT_APPROVED - record attempting to post has a status not equal to approved
-
ALREADY_UNPOSTED - record you are attempting to unpost is not posted
-
CREDITS_DEBITS_NOT_EQUAL - total number of credits do not equal total number of debits for the journal entry
-
CLEARED_BANK_RECONCILIATION - attempted to unpost a journal entry that has a journal entry line associated with a bank reconciliation
-
CLEARED_BANK_DEPOSIT - attempted to unpost a journal entry that has a journal entry line associated with a bank deposit
// Create account payable records to post and unpost
AcctSeed__Journal_Entry__c[] journalEntries = new List <AcctSeed__Journal_Entry__c>();
journalEntries.add(
new AcctSeed__Journal_Entry__c(
Name = 'My Journal Entry 1'
)
);
journalEntries.add(
new AcctSeed__Journal_Entry__c(
Name = 'My Journal Entry 2'
)
);
insert journalEntries;
// Create journal entry line records to post and unpost
AcctSeed__Journal_Entry_Line__c[] jeLines = new List <AcctSeed__Journal_Entry_Line__c> ();
List<AcctSeed__GL_Account__c> glAccounts = [Select Id From AcctSeed__GL_Account__c limit 2];
for (AcctSeed__Journal_Entry__c journalEntry : journalEntries) {
AcctSeed__Journal_Entry_Line__c objJournalEntryLine = new AcctSeed__Journal_Entry_Line__c();
objJournalEntryLine.AcctSeed__Journal_Entry__c = journalEntry.id;
objJournalEntryLine.AcctSeed__Debit__c = 25;
objJournalEntryLine.AcctSeed__GL_Account__c = glAccounts[0].Id;
objJournalEntryLine.AcctSeed__Account__c = [select id from account limit 1].id;
jeLines.add(objJournalEntryLine);
objJournalEntryLine = new AcctSeed__Journal_Entry_Line__c();
objJournalEntryLine.AcctSeed__Journal_Entry__c = journalEntry.id;
objJournalEntryLine.AcctSeed__Credit__c = 25;
objJournalEntryLine.AcctSeed__GL_Account__c = glAccounts[1].Id;
objJournalEntryLine.AcctSeed__Account__c = [select id from account limit 1].id;
jeLines.add(objJournalEntryLine);
}
insert jeLines;
// Call the post journal entry service
AcctSeed.PostResult[] postResults = AcctSeed.JournalEntryPostService.postJournalEntries(journalEntries);
// Loop through post results
for (AcctSeed.PostResult theResult : postResults) {
if (theResult.isSuccess) {
System.debug('Successfully posted journal entry: ' + theResult.id);
}
else {
System.debug('Error posting billing ' + theResult.id);
for (AcctSeed.PostResult.PostErrorResult errorResult: theResult.errors) {
System.debug('Error status code ' + errorResult.statusCode);
System.debug('Error message ' + errorResult.message);
}
}
}
// Call the unpost journal entry service
AcctSeed.PostResult[] unpostResults = AcctSeed.JournalEntryPostService.unpostJournalEntries(journalEntries);
// Loop through unpost results
for (AcctSeed.PostResult theResult : unpostResults) {
if (theResult.isSuccess) {
System.debug('Successfully unposted journal entry: ' + theResult.id);
}
else {
System.debug('Error unposting journal entry ' + theResult.id);
for (AcctSeed.PostResult.PostErrorResult errorResult: theResult.errors) {
System.debug('Error status code ' + errorResult.statusCode);
System.debug('Error message ' + errorResult.message);
}
}
}
Comments
0 comments
Article is closed for comments.