Accelerator Salesforce Financial Account Event Listener - Implementation Template
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
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:
- accel-account-update-exchange
- accel-account-update-dl-queue
- accel-transaction-update-exchange
- accel-transaction-update-dl-queue
- accel-card-update-exchange
- 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:
- Login to Salesforce.
- Click Setup to search for Platform Events in Quick Find Box. Platform Events Page under Integrations section appears with list of available Platform Events.
- Click New Platform Event button to create an Object and enter Platform Information Details fields like Label, Plural Label and Object. Click Save.
- 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 Label | API Name | Data Type |
---|---|---|
CreatedDate | CreatedDate__c | Date/Time |
CurrencyIsoCode | CurrencyIsoCode__c | Text(80) |
FinServ__Balance | FinServ_Balance__c | Number(16, 2) |
FinServ__CashBalance | FinServ_CashBalance__c | Number(16, 2) |
FinServ__CloseDate | FinServ_CloseDate__c | Date |
FinServ__FinancialAccountNumber | FinServ_FinancialAccountNumber__c | Text(80) |
FinServ__FinancialAccountType | FinServ_FinancialAccountType__c | Text(80) |
FinServ__InterestRate | FinServ_InterestRate__c | Number(3, 2) |
FinServ__JointOwner | FinServ_JointOwner__c | Text(36) |
FinServ__LastTransactionDate | FinServ_LastTransactionDate__c | Date/Time |
FinServ__LoanAmount | FinServ_LoanAmount__c | Number(16, 2) |
FinServ__LoanTermMonths | FinServ_LoanTermMonths__c | Number(3, 2) |
FinServ__MinimumBalance | FinServ_MinimumBalance__c | Number(16, 2) |
FinServ__MinimumPayment | FinServ_MinimumPayment__c | Number(16, 2) |
FinServ__OpenDate | FinServ_OpenDate__c | Date |
FinServ__PrimaryOwner | FinServ_PrimaryOwner__c | Text(80) |
FinServ__PrincipalBalance | FinServ_PrincipalBalance__c | Number(16, 2) |
FinServ__RecordTypeName | FinServ_RecordTypeName__c | Text(80) |
FinServ__RoutingNumber | FinServ_RoutingNumber__c | Text(80) |
FinServ__Status | FinServ_Status__c | Text(80) |
FinServ__TaxID | FinServ_TaxID__c | Text(80) |
FinServ__TotalCreditLimit | FinServ_TotalCreditLimit__c | Number(16, 2) |
FinServ_Nickname | FinServ_Nickname__c | Text(80) |
Global_Account_Id | Global_Account_Id__c | Text(36) |
Id | Id__c | Text(36) |
Initial_Transaction_Id | Initial_Transaction_Id__c | Text(80) |
IsDeleted | IsDeleted__c | Checkbox |
Last_Transaction_Id | Last_Transaction_Id__c | Text(36) |
LastModifiedDate | LastModifiedDate__c | Date/Time |
LastPaymentAmount | LastPaymentAmount__c | Number(16, 2) |
LastPaymentDate | LastPaymentDate__c | Date |
LastStatementDate | LastStatementDate__c | Date |
LastTransactionAmount | LastTransactionAmount__c | Number(16, 2) |
Maximum_Monthly_Withdrawals | Maximum_Monthly_Withdrawals__c | Number(18, 0) |
Monthly_Withdrawal_Limit | Monthly_Withdrawal_Limit__c | Number(16, 2) |
Name | Name__c | Text(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 Label | API Name | Data Type |
---|---|---|
CreatedDate | CreatedDate__c | Date/Time |
Credit_Financial_Account | Credit_Financial_Account__c | Text(36) |
CurrencyIsoCode | CurrencyIsoCode__c | Text(80) |
Debit_Financial_Account | Debit_Financial_Account__c | Text(36) |
FinServ_Amount | FinServ_Amount__c | Number(16, 2) |
FinServ_Description | FinServ_Description__c | Text(255) |
FinServ_DisputeReason | FinServ_DisputeReason__c | Text(255) |
FinServ_FinancialAccount | FinServ_FinancialAccount__c | Text(36) |
FinServ_IsDisputed | FinServ_IsDisputed__c | Checkbox |
FinServ_PostDate | FinServ_PostDate__c | Date/Time |
FinServ_TransactionDate | FinServ_TransactionDate__c | Date/Time |
FinServ_TransactionId | FinServ_TransactionId__c | Text(80) |
FinServ_TransactionStatus | FinServ_TransactionStatus__c | Text(100) |
FinServ_TransactionSubtype | FinServ_TransactionSubtype__c | Text(100) |
FinServ_TransactionType | FinServ_TransactionType__c | Text(100) |
Global_Transaction_Id | Global_Transaction_Id__c | Text(36) |
Id | Id__c | Text(36) |
IsDeleted | IsDeleted__c | Checkbox |
LastModifiedDate | LastModifiedDate__c | Date/Time |
Name | Name__c | Text(80) |
Originator_Id | Originator_Id__c | Text(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 Label | API Name | Data Type |
---|---|---|
Card_Type | Card_Type__c | Text(100) |
Cardholder_Name | Cardholder_Name__c | Text(100) |
CreatedDate | CreatedDate__c | Date/Time |
Credit_Card_Type | Credit_Card_Type__c | Text(100) |
FinServ_AccountHolder | FinServ_AccountHolder__c | Text(36) |
FinServ_Active | FinServ_Active__c | Checkbox |
FinServ_BinNumber | FinServ_BinNumber__c | Number(16, 0) |
FinServ_FinancialAccount | FinServ_FinancialAccount__c | Text(36) |
FinServ_ValidUntil | FinServ_ValidUntil__c | Date |
Global_Card_Id | Global_Card_Id__c | Text(36) |
Id | Id__c | Text(36) |
IsDeleted | IsDeleted__c | Checkbox |
LastModifiedDate | LastModifiedDate__c | Date/Time |
Name | Name__c | Text(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.
- Click on Salesforce Setup icon and select
Developer Console
to open a new console window - Go to
File -> New -> Apex class
and create a new class namedCustomFieldUtility
- Copy the code from
accelerator-common-resources/salesforce/CustomFieldUtility.apxc
to the script editor - Select the
File -> Save
menu option to compile and save the class - Select
Debug -> Open Execute Anonymous Window
- Copy and paste the contents of
accelerator-common-resources/salesforce/CreatePlatformEventsCustomFields.txt
into the window. - 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 Object | Salesforce Platform Event Object | Apex Trigger Name | Apex Trigger script location |
---|---|---|---|
FinServ__FinancialAccount__c | FinancialAccount | FinancialAccountEventsPub | /src/test/resources/scripts/financial-accounts-event-publisher.apxt |
FinServ__FinancialAccountTransaction__c | FinancialAccountTransaction | TransactionsEventsPub | /src/test/resources/scripts/transactions-event-publisher.apxt |
FinServ__Card__c | FinancialCard | CardsEventsPub | /src/test/resources/scripts/cards-event-publisher.apxt |
Follow the below steps to create the Apex Triggers:
- Login to Salesforce.
- Click Setup to search for Object Manager in Quick Find Box.
- Search for the Salesforce Object. A page appears with Details of the Object.
- Click Triggers unders the Details section to see list of available triggers on the Object. Click New.
- Copy the Script from the location specified in the above table .
- Obtain the
LastModifiedById
andRecordTypeId
(if it exists) by running the queries mentioned in the trigger from Developer Console. - Replace the values in the script and Save the trigger
- 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 querySELECT 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 Name | Description |
---|---|
anypoint-mq.client-id | Anypoint MQ Client Id |
anypoint-mq.client-secret | Anypoint MQ Client Id |
sfdc.username | Salesforce Instance client user Name |
sfdc.token | Salesforce Instance client token |
sfdc.password | Salesforce Instance client password |
sfdc.client-id | The Consumer Id of the Connected App in Salesforce |
sfdc.client-secret | The Consumer secret of the Connected App in Salesforce |
sfdc.update-source | Name of the Source Salesforce Instance from where the Events are triggered |
Implementation notes
- 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.
- 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.
- The current implementation does not support replay of Platform Events that were missed when the Mule application is down.
Additional resources
- The Data mappings tab describes how the request and response data structures are mapped between the API interfaces.
- Refer to the Accelerators documentation home for more information about the MuleSoft Accelerators.