Show/Hide Toolbars

Use AccountService when working with account records.

Whenever a Service operation requires AccountService, set up AccountService using the following code:

AccountService accountService = platform.getAccountService();

Creating an Account

The following sample creates an account record. During account creation, you can set objects in the account record, such as the account name.

Account newAccount = accountService.newAccount("name", allocationLimit, startOnDate, endOnDate);

Creating a Child Account

The following sample creates a child account record. During child account creation, you can use API interface methods to set objects in the account, such as the parent account.

Account newChildAccount = accountService.newAccount("name", allocationLimit, startOnDate, endOnDate);

newChildAccount.setParentAccount(parentAccount);

Reading an Account

The following sample reads an account record. When you read an account, you retrieve the account so that you can make changes to it, such as activating or transferring money from it.

//The id initialized here is the id of an existing account

Long id = 1234567890L;

Account account = accountService.read(id);

Activating an Account

The following sample activates an account record.

accountService.activateAccount(accountToBeActivated);

Deactivating an Account

The following sample deactivates an account record.

accountService.deactivateAccount(account);

Allocating Money to an Account

The following sample allocates money to an account record. When you allocate money to an account, a parent account must already exist.

//Allocating money to an account - $5000

accountService.allocateMoney(account, amount, "description");

Transferring Money between Accounts

The following sample transfers money between two accounts. When you transfer money, a parent and child account must already exist.

accountService.transferMoney(accountFrom, accountTo, amount, "description");

Withdrawing money from an Account

The following sample withdraws money from an account record.

//Withdrawing from an account - $5000

accountService.withdrawMoney(account, new BigDecimal("5000"), "Withdraw to zero");

Deleting an Account

The following sample deletes an account record. When you delete an account, the account must not have a balance.

//Account cannot have a balance before deletion. Make necessary withdrawals.

accountService.withdrawMoney(parentAccount, new BigDecimal("1000"), "Withdraw to zero");

accountService.withdrawMoney(childAccount, new BigDecimal("234"), "Withdraw to zero");

 

//When deleting a parent account with attached child accounts, the child accounts also cannot have a balance. The deletion of a parent will delete its child accounts as well.

accountService.delete(parentAccount);