Accelerator Salesforce Financial Account Event Listener - Implementation Template

(0 reviews)

home

This API implementation template is a component of MuleSoft Accelerators, which accelerate the implementation of essential integration use cases.

The solution includes pre-built APIs, connectors, and integration templates that help unlock business-critical data from external systems and guide you in adopting best practices synthesized from thousands of customer implementations. Use these assets as is or extend them to meet your company’s unique needs.


Overview

The following functionality is supported by the Salesforce Financial Account Event Listener application.

Financial account event listener

This event listener is subscribed to the Platform Event channel configured in Salesforce with API Name as FinancialAccounte. A Trigger generates an Event based on changes to Accounts in FinServFinancialAccount__c Object. The trigger filters records based on LastModifiedBy <> Service Account User ID to avoid cyclical updates.

The fields in the Platform Event include financial account information. These fields are received as JSON Objects from Salesforce and transformed to CIM data type (Accounts) and published to Anypoint MQ. In case of any failure the incoming original payload is published to the dead letter queue by the exception handler.

Transactions event listener

This event listener is subscribed to the Platform Event channel configured in Salesforce with API Name as FinancialAccountTransactione. A Trigger generates an Event based on changes to Transactions in FinServFinancialAccountTransaction__c Object. The trigger filters records based on LastModifiedBy <> Service Account User ID to avoid cyclical updates.

The fields in the Platform Event include financial transaction information. These fields are received as JSON Objects from Salesforce and transformed to CIM data type (Accounts) and published to Anypoint MQ. In case of any failure the incoming original payload is published to the dead letter queue by the exception handler.

Cards event listener

This event listener is subscribed to the Platform Event channel configured in Salesforce with API Name as FinancialAccountTransactione. A Trigger generates an Event based on changes to cards in FinServCard__c Object. The trigger filters records based on LastModifiedBy <> Service Account User ID to avoid cyclical updates.

The fields in the Platform Event include cards information. These fields are received as JSON Objects from Salesforce and transformed to CIM data type (Accounts) and published to Anypoint MQ. In case of any failure the incoming original payload is published to the dead letter queue by the exception handler.

Getting started

bulb.png The Getting Started with MuleSoft Accelerators guide provides general information on getting started with the accelerator components. This includes instructions on setting up your local workstation for configuring and deploying the applications.

Once your workstation has been set up and the application template imported into Anypoint Studio, proceed with the Prerequisites section.

Prerequisites

This implementation template has the following dependencies:

  • Anypoint MQ Destinations
  • Salesforce Platform Events
  • Salesforce Apex Triggers

Please review the use cases described on the MuleSoft Accelerators solution pages for more information about dependencies on other APIs and services.

Anypoint MQ destinations

In addition to the Anypoint MQ client application credentials, the following destinations must be created and made accessible to this API:

  1. accel-account-update-exchange
  2. accel-account-update-dl-queue
  3. accel-transaction-update-exchange
  4. accel-transaction-update-dl-queue
  5. accel-card-update-exchange
  6. accel-card-update-dl-queue

Salesforce Platform Events

This implementation requires creation of Platform Events in Salesforce. To create a Platform event Object following the below steps:

  1. Login to Salesforce.
  2. Click Setup to search for Platform Events in Quick Find Box. Platform Events Page under Integrations section appears with list of available Platform Events.
  3. Click New Platform Event button to create an Object and enter Platform Information Details fields like Label, Plural Label and Object. Click Save.
  4. Enter Custom Fields & RelationShips to create Event with specific defintions.

Platform Event Definition for Financial Account PlatformEvent

Create a Platform Event with Label as FinancialAccountPlatformEvent, Object as FinancialAccount and Custom Fields & RelationShips as per below table. These Custom fields can also be created via apex script and the instructions are included in Create Custom Fields via Apex script section below.

Field LabelAPI NameData Type
CreatedDateCreatedDate__cDate/Time
CurrencyIsoCodeCurrencyIsoCode__cText(80)
FinServ__BalanceFinServ_Balance__cNumber(16, 2)
FinServ__CashBalanceFinServ_CashBalance__cNumber(16, 2)
FinServ__CloseDateFinServ_CloseDate__cDate
FinServ__FinancialAccountNumberFinServ_FinancialAccountNumber__cText(80)
FinServ__FinancialAccountTypeFinServ_FinancialAccountType__cText(80)
FinServ__InterestRateFinServ_InterestRate__cNumber(3, 2)
FinServ__JointOwnerFinServ_JointOwner__cText(36)
FinServ__LastTransactionDateFinServ_LastTransactionDate__cDate/Time
FinServ__LoanAmountFinServ_LoanAmount__cNumber(16, 2)
FinServ__LoanTermMonthsFinServ_LoanTermMonths__cNumber(3, 2)
FinServ__MinimumBalanceFinServ_MinimumBalance__cNumber(16, 2)
FinServ__MinimumPaymentFinServ_MinimumPayment__cNumber(16, 2)
FinServ__OpenDateFinServ_OpenDate__cDate
FinServ__PrimaryOwnerFinServ_PrimaryOwner__cText(80)
FinServ__PrincipalBalanceFinServ_PrincipalBalance__cNumber(16, 2)
FinServ__RecordTypeNameFinServ_RecordTypeName__cText(80)
FinServ__RoutingNumberFinServ_RoutingNumber__cText(80)
FinServ__StatusFinServ_Status__cText(80)
FinServ__TaxIDFinServ_TaxID__cText(80)
FinServ__TotalCreditLimitFinServ_TotalCreditLimit__cNumber(16, 2)
FinServ_NicknameFinServ_Nickname__cText(80)
Global_Account_IdGlobal_Account_Id__cText(36)
IdId__cText(36)
Initial_Transaction_IdInitial_Transaction_Id__cText(80)
IsDeletedIsDeleted__cCheckbox
Last_Transaction_IdLast_Transaction_Id__cText(36)
LastModifiedDateLastModifiedDate__cDate/Time
LastPaymentAmountLastPaymentAmount__cNumber(16, 2)
LastPaymentDateLastPaymentDate__cDate
LastStatementDateLastStatementDate__cDate
LastTransactionAmountLastTransactionAmount__cNumber(16, 2)
Maximum_Monthly_WithdrawalsMaximum_Monthly_Withdrawals__cNumber(18, 0)
Monthly_Withdrawal_LimitMonthly_Withdrawal_Limit__cNumber(16, 2)
NameName__cText(80)

Platform Event Definition for Financial Account Transaction PlatformEvent

Create a Platform Event with Label as FinancialAccountTransactionPlatformEvent, Object as FinancialAccountTransaction, and Custom Fields & RelationShips as per below table. These Custom fields can also be created via Apex script - instructions are included in the "Create Custom Fields via Apex script section", below.

Field LabelAPI NameData Type
CreatedDateCreatedDate__cDate/Time
Credit_Financial_AccountCredit_Financial_Account__cText(36)
CurrencyIsoCodeCurrencyIsoCode__cText(80)
Debit_Financial_AccountDebit_Financial_Account__cText(36)
FinServ_AmountFinServ_Amount__cNumber(16, 2)
FinServ_DescriptionFinServ_Description__cText(255)
FinServ_DisputeReasonFinServ_DisputeReason__cText(255)
FinServ_FinancialAccountFinServ_FinancialAccount__cText(36)
FinServ_IsDisputedFinServ_IsDisputed__cCheckbox
FinServ_PostDateFinServ_PostDate__cDate/Time
FinServ_TransactionDateFinServ_TransactionDate__cDate/Time
FinServ_TransactionIdFinServ_TransactionId__cText(80)
FinServ_TransactionStatusFinServ_TransactionStatus__cText(100)
FinServ_TransactionSubtypeFinServ_TransactionSubtype__cText(100)
FinServ_TransactionTypeFinServ_TransactionType__cText(100)
Global_Transaction_IdGlobal_Transaction_Id__cText(36)
IdId__cText(36)
IsDeletedIsDeleted__cCheckbox
LastModifiedDateLastModifiedDate__cDate/Time
NameName__cText(80)
Originator_IdOriginator_Id__cText(36)

Platform Event Definition for Financial Card PlatformEvent

Create a Platform Event with Label as FinancialCardPlatformEvent, Object as FinancialCard and Custom Fields & RelationShips as per below table. As mentioned above, these Custom fields can also be created via Apex script.

Field LabelAPI NameData Type
Card_TypeCard_Type__cText(100)
Cardholder_NameCardholder_Name__cText(100)
CreatedDateCreatedDate__cDate/Time
Credit_Card_TypeCredit_Card_Type__cText(100)
FinServ_AccountHolderFinServ_AccountHolder__cText(36)
FinServ_ActiveFinServ_Active__cCheckbox
FinServ_BinNumberFinServ_BinNumber__cNumber(16, 0)
FinServ_FinancialAccountFinServ_FinancialAccount__cText(36)
FinServ_ValidUntilFinServ_ValidUntil__cDate
Global_Card_IdGlobal_Card_Id__cText(36)
IdId__cText(36)
IsDeletedIsDeleted__cCheckbox
LastModifiedDateLastModifiedDate__cDate/Time
NameName__cText(80)

Create Custom Fields via Apex script

An Apex class called CustomFieldUtility can be used to create custom fields programmatically. The source for this class can be found in the Common Resources project. Download this project and follow the steps below.

  1. Click on Salesforce Setup icon and select Developer Console to open a new console window
  2. Go to File -> New -> Apex class and create a new class named CustomFieldUtility
  3. Copy the code from accelerator-common-resources/salesforce/CustomFieldUtility.apxc to the script editor
  4. Select the File -> Save menu option to compile and save the class
  5. Select Debug -> Open Execute Anonymous Window
  6. Copy and paste the contents of accelerator-common-resources/salesforce/CreatePlatformEventsCustomFields.txt into the window.
  7. Enable the Open Log option and click the Execute button.

Once the script completes, select the Debug Only filter option to show just the results of each create request. Verify that all fields have been successfully created.

Note: Do not execute all the content in the CreatePlatformEventsCustomFields.txt file at once as the console might throw a timeout error. Instead execute it in batches.

Salesforce Apex Triggers

This implementation requires creation of Apex Triggers for the Platform Events to be generated on changes to records in Salesforce.

Salesforce ObjectSalesforce Platform Event ObjectApex Trigger NameApex Trigger script location
FinServ__FinancialAccount__cFinancialAccountFinancialAccountEventsPub/src/test/resources/scripts/financial-accounts-event-publisher.apxt
FinServ__FinancialAccountTransaction__cFinancialAccountTransactionTransactionsEventsPub/src/test/resources/scripts/transactions-event-publisher.apxt
FinServ__Card__cFinancialCardCardsEventsPub/src/test/resources/scripts/cards-event-publisher.apxt

Follow the below steps to create the Apex Triggers:

  1. Login to Salesforce.
  2. Click Setup to search for Object Manager in Quick Find Box.
  3. Search for the Salesforce Object. A page appears with Details of the Object.
  4. Click Triggers unders the Details section to see list of available triggers on the Object. Click New.
  5. Copy the Script from the location specified in the above table .
  6. Obtain the LastModifiedById and RecordTypeId (if it exists) by running the queries mentioned in the trigger from Developer Console.
  7. Replace the values in the script and Save the trigger
  8. Repeat the steps for all the Salesforce objects in the above table

Additional notes:

  • All the Apex Triggers created above filters records based on LastModifiedBy <> {Service account ID}. This is to filter out updates done by the Salesforce Customers and Salesforce Financial System APIs to avoid cyclical updates. This can be obtained by running the query SELECT Id FROM User WHERE Username='<service-account-username>' in the Developer Console.

Deployment

Each Accelerator implementation template in Exchange includes Bash and Windows scripts for building and deploying the APIs to CloudHub. These scripts depend on repositories, global settings, deployment profiles, and associated properties configured in the Maven settings.xml file.

For additional details, please refer to the Application Deployment section of the Getting Started Guide.

Preparation

Ensure the Maven profile CloudHub-DEV has been properly configured in your settings.xml file. In particular, make sure the common properties for your environment have been provided (e.g., Anypoint Platform client ID and secret).

Required property overrides

At a minimum, the following properties must be customized to reflect the target deployment environment.

Property NameDescription
anypoint-mq.client-idAnypoint MQ Client Id
anypoint-mq.client-secretAnypoint MQ Client Id
sfdc.usernameSalesforce Instance client user Name
sfdc.tokenSalesforce Instance client token
sfdc.passwordSalesforce Instance client password
sfdc.client-idThe Consumer Id of the Connected App in Salesforce
sfdc.client-secretThe Consumer secret of the Connected App in Salesforce
sfdc.update-sourceName of the Source Salesforce Instance from where the Events are triggered

Implementation notes

  1. The fields 'Account Holder', 'Card Type', 'Financial Account', and 'Cardholder Name' are optional in FSC. For the cards sync process, these fields are mandatory for syncing to all downstream APIs.
  2. The Mule idempotent message validator is used to ensure that only unique messages are published to Anypoint MQ. The Salesforce ID with an expiration interval and time-to-live (ttl) of 30 seconds (configurable) is used as the unique ID to filter out duplicate Mule messages.
  3. The current implementation does not support replay of Platform Events that were missed when the Mule application is down.

Additional resources


Reviews

TypeTemplate
OrganizationMuleSoft
Published by
MuleSoft Solutions
Published onNov 8, 2023
Asset overview

Asset versions for 1.0.x

Asset versions
VersionActions
1.0.3
1.0.1
1.0.0