Hands-On with Financial Services Cloud: Building and Extending with Custom Functionality

This is the second installment of our blog series that focuses on building apps on Financial Services Cloud. In our first installment, we gave background on Financial Services Cloud and showed why customers and ISVs should build apps to extend it. In this article, we get hands-on with a use case and show you how to extend Financial Services Cloud with custom functionality to connect with the DriveWealth open API.

Project objectives

  • Integrate with a third-party open API (DriveWealth)
  • Build Lightning components to extend base Financial Services Cloud UI
  • Build object-oriented, reusable, extensible code
  • Build secure and scalable code
  • Build a sample extension package on Financial Services Cloud

Application architecture

As illustrated in the architecture, the primary user personas are financial advisors; system administrators who are regular Force.com users; and the end customers, who can be the investors or household members advised by the financial advisor. These end customers can be customer community users.

We progressively build out the managed package components as we go through this project.

What exactly is DriveWealth ?

DriveWealth is a mobile investing platform for young investors. It specializes in investing in fractional shares. For more details, visit https://drivewealth.com.

DriveWealth provides a free open API for developers supporting REST and FIX (financial info exchange) APIs. In our sample project, we use the DriveWealth REST API to integrate with Salesforce.

Project use cases and DriveWealth APIs

For the first phase of this project we focus on the following use cases for the financial advisor user persona:

  • Create a DriveWealth account (practice account)
  • Search for a ticker symbol for a stock
  • Place a market order for a stock
  • Get the market order status

Some of the DriveWealth APIs that we use for these use cases include:

Prerequisites

  • Salesforce Developer org with Financial Services Cloud installed:
    • Sign up for a free Developer Edition. Partners can create a new Partner Developer Edition from their business org. (ISV partners can reach out to their partner account manager to get access to Financial Services Cloud.)
    • Prepare your Developer Edition for Lightning component development (enable My Domain and Deploy to Users).
  • Financial Services Cloud installation is configured correctly. Follow the instructions closely in the quick start guide to configure the org and create the requisite profiles.
  • DriveWealth account setup for development. Send an email to partner@drivewealth.com to set up your account.
  • Familiarity with development of Lightning components
  • Familiarity with Apex development and callouts

Demo

To take a look at how the application looks, review this brief video.

Tools and frameworks

We use the following frameworks to make our lives a bit easier. Note that these are the individual choices of the authors of this blog and not an endorsement by Salesforce.

Implementation details

Use Case 1: Create a DriveWealth Account

The sequence diagram provides a high-level illustration of the interaction between the various components of the application.

Lets look at the code for this use case. All the source code is available on GitHub. Here are the relevant code components:

  • DemoApp.app application:
    • This stand-alone app container facilitates testing of components without having to use one.app container and load the entire Lightning Experience interface.
    • The DemoApp loads DriveWealth account information on initialization.
  • DWCreateAccountForm.cmp:
    • The component that collects the information needed by the DriveWealth API to create a DriveWealth practice account, including first name, last name, user name, and password.
    • This DriveWealth account is needed for creating market orders.
    • This component invokes the the JavaScript controller DWCreateAccountFormController.js and the associated helper JavaScript class DWCreateAccountFormHelper.js, which in turn invokes the Apex controller class DWCreateAccount.cls.
  • DWCreateAccount.cls:
    • The controller class that prepares the DriveWealth account and makes the callout to the DriveWealth API to create the DriveWealth account.

Design patterns and usage

The Create DriveWealth Account use case employs the excellent design pattern framework designed by Andres Perez.

This pattern helps manage the communication between Lightning components and Apex:

This illustrates the reusability of this pattern.

As an example in this project, the createAccount function (DWCreateAccountFormHelper.js file) of our component finds and invokes the component ETLC_ApexBridge.cmp, which in turn invokes the “execute” method in the class ETLC_ApexBridge_Controller.

createAccount: function(component, helper) {
        if(helper.isValid(component, helper) && component.isValid()) {

            component.find('utils').toggleSpinner(component.find('spinner'), true);

            var apexBridge = component.find("ApexBridge");

            apexBridge.callApex({
                component: component,
                data: {
                    operation: "DWCreateAccount",
                    input: {
                        acc: component.get('v.acc'),
                        FirstName: component.get('v.fname'),
                        LastName: component.get('v.lname'),
                        UserName: component.get('v.uname'),
                        Password: component.get('v.passwd'),
                        mode: 'createAccount'
                    }
                },

The execute method uses reflection to determine the class to be instantiated at runtime and executes the process method.

public with sharing  class ETLC_ApexBridge_Controller {
    @AuraEnabled
    public static String execute(String dataJson) {
        ETLC_ApexBridge_Data data;
        try {
            data = ETLC_ApexBridge_Data.fromJSON(dataJson);
            ETLC_ApexBridge_Abstract executor = (ETLC_ApexBridge_Abstract) Type.forName(data.operation).newInstance();
            executor.process(data);
        } catch (Exception ex) {

In this case, the class instantiated is our Apex controller DWCreateAccount.cls, and the corresponding process method is invoked.

public override void process(ETLC_ApexBridge_Data data) {
        //Set debugging
        if (data.debug) {
            Util.debug = data.debug;
        }

        // Depending on the mode, determine which operation to perform

        String mode = (String) data.getInputValue('mode');
        if (mode == 'getAccount') {
            data.output = ETLC_ApexBridge_Data.encodeData(getAccount((Id) data.getInputValue('AccountID')));
        } else if (mode == 'createAccount') {
            Util.log('DWCreateAccount.process():data: ' + data);
            Util.log(data.getInputValue('acc'));
            data.output = ETLC_ApexBridge_Data.encodeData(
                    createAccount( data,
                            (Map<String, Object>) data.getInputValue('acc'),
                            (String)  data.getInputValue('FirstName'),
                            (String)  data.getInputValue('LastName'),
                            (String)  data.getInputValue('UserName'),
                            (String)  data.getInputValue('Password')
                    )
            );
        }
    }

This pattern can be used by any component that you write in your project. This pattern helps you cut down the amount of code to write invoking controllers from components.

Whats next in this blog series

In the next part of this blog series, we explore the other use cases of the project. We also dig a little deeper into the usage of the ESAPI library to make our code secure to help pass the Salesforce security review. In addition, we provide details on the logging mechanism used and provide some insight into what we will work on next as we continue augmenting the project.

Summary

In this article, you learned how to extend Financial Services Cloud by creating your own component to integrate with a third-party open API. You have access to our entire codebase on GitHub. Get it, experiment with it, and post your questions/comments below.

The Blog Team Behind This Series

Vydianath Iyer
Jaswinder Rattanpal

Related links

Published
June 13, 2017

Leave your comments...

Hands-On with Financial Services Cloud: Building and Extending with Custom Functionality