Masaryk University Faculty of Informatics

Integration of 3rd party applications into CRM

Master’s Thesis

Jakub Hančin

Brno, Spring 2020 Masaryk University Faculty of Informatics

Integration of 3rd party applications into Salesforce CRM

Master’s Thesis

Jakub Hančin

Brno, Spring 2020 This is where a copy of the official signed thesis assignment and a copy ofthe Statement of an Author is located in the printed version of the document. Declaration

Hereby I declare that this paper is my original authorial work, which I have worked out on my own. All sources, references, and literature used or excerpted during elaboration of this work are properly cited and listed in complete reference to the due source.

Jakub Hančin

Advisor: RNDr. Josef Spurný

i Acknowledgements

My first great thanks goes to my soon-to-be wife Miriam Kanovská who was extremely supportive during the creation of this thesis and who will hopefully not change her mind about marrying me once the defence of this thesis is over. A large thanks go to my supervisor Josef Spurný, who was a great lecturer of mine and who was seemingly the only person in the entire Faculty of Informatics willing to supervise such a specific thesis as mine was. Big thanks goes to my former colleagues at the Enehano company in Prague who taught me nearly everything you can find in the practi- cal as well as theoretical part of this thesis. Great thanks goes to Jiří Mach and Michal Peška, who founded an extraordinary company and turned out to be the most pleasurable bosses I have ever had. Another huge thank you goes to Michal Mach and Milan Bodlák, my fellow developer colleagues at Enehano who were willing to give me advice whenever I needed it. And big thank you goes to Craig Jordan and the LeanTaaS company who allowed me to use an example fitting a master’s thesis on such a topic perfectly. And the one person I cannot forgot is my uncle Miroslav Barus who had the patience to lecture me during weekends during my first year at FI and without whom I would probably never become an IT graduate.

ii Abstract

CRM platform development as a market is rapidly growing the already rapidly growing IT industry. This thesis focuses on the current CRM market leader Salesforce and with the help of a practical example which demonstrates the possibilities of this platform. The practical example is a functional 3rd party integration applica- tion developed under the wings of the SaaScend company for a client called LeanTaaS. This example shows how to integrate a JSON data source into Salesforce on an automatic and periodical basis. Not only does this thesis summarize the technical difficulties of performing such a task but it also provides a detailed walkthrough on the development steps required to take prior to deploying the developed code to production. The purpose of this thesis is to help any beginner Salesforce or Java developers who were given the task to integrate two or multiple different systems together to get a better grasp of the problem, propose possible solutions and potentially provide a good starting point on the analysis front as the principles of building such an integration remain nearly always the same.

iii Keywords

Salesforce, CRM, Apex, REST, API, Integration, Org, Schedulable, Change Set, Production, Sandbox, Multitenancy, SOQL, SOSL, Trail- head, Dreamforce, Pulling, Pushing, The Welkin Suite, Visual Studio, Access token, Bearer Token, Http, CRON, Script, Salesforce Developer console

iv Contents

Introduction 1

1 CRM platforms introduction 2 1.1 What is a CRM ...... 2 1.2 CRM adoption ...... 2 1.3 CRM platform market ...... 3 1.4 Economic relevance of the CRM market ...... 4 1.5 Subscription-based CRM platforms ...... 5 1.5.1 Salesforce CRM ...... 5 1.5.2 SAP CRM ...... 6 1.5.3 Oracle CRM ...... 7 1.5.4 Microsoft Dynamics CRM ...... 8 1.6 CRM platforms with a free plan ...... 9 1.6.1 HubSpot CRM ...... 9 1.6.2 Zoho CRM ...... 10 1.7 CRM platforms comparison ...... 11

2 Salesforce CRM 13 2.1 History ...... 13 2.2 Salesforce - community specifics ...... 14 2.2.1 Trailhead - the Salesforce learning platform . . . 14 2.2.2 Dreamforce - the Salesforce yearly conference . 15 2.3 Salesforce - technological specifics ...... 16 2.3.1 Multitenancy ...... 16 2.3.2 Limits ...... 16 2.3.3 Apex - Salesforce programming language . . . . 17 2.3.4 SOQL - Salesforce Object Query Language . . . 18 2.3.5 SOSL - Salesforce Object Search Lanuage . . . . 19

3 Integrations - implementation approaches 20 3.1 Introduction ...... 20 3.2 Pulling ...... 20 3.2.1 Requirements ...... 21 3.2.2 Advantages ...... 21 3.2.3 Disadvantages ...... 21 3.3 Pushing ...... 22

v 3.3.1 Requirements ...... 22 3.3.2 Advantages ...... 23 3.3.3 Disadvantages ...... 23 3.4 Conclusion ...... 24

4 Author REST application - case study 25 4.1 Introduction ...... 25 4.1.1 Context ...... 25 4.1.2 Project context ...... 25 4.1.3 Description of the objective ...... 26 4.1.4 Project - team & pre-project analysis ...... 26 4.2 Obstacles to overcome ...... 27 4.2.1 Data heterogeneity ...... 27 4.2.1.1 Solution ...... 27 4.2.2 URL encoding query requirement ...... 28 4.2.2.1 Solution ...... 28 4.2.3 Periodicity ...... 28 4.2.3.1 Solution ...... 28 4.2.4 Authorization ...... 29 4.2.4.1 Solution ...... 29

5 Author REST application - pre-development setup 32 5.1 Sandbox - testing environment ...... 32 5.1.1 Configuration ...... 32 5.1.2 Change set - uploading changes from a sandbox to production ...... 33 5.2 Org preparation ...... 34 5.2.1 Custom object creation ...... 34 5.2.2 Custom field creation ...... 35 5.3 Suitable IDE ...... 37 5.3.1 Developer console - native Salesforce tool . . . . 37 5.3.2 The Welkin Suite - external IDE based on Visu- alStudio ...... 37

6 Author REST application - implementation 39 6.1 Introduction ...... 39 6.1.1 Overview of the functionality ...... 39 6.1.2 Restrictions in possible recreation ...... 39

vi 6.1.3 Structure of code analysis ...... 39 6.2 Project structure ...... 40 6.2.1 Integration functionality - code hierarchy . . . . 40 6.2.2 Test class - mandatory unit tests ...... 42 6.3 Code Analysis ...... 44 6.3.1 Data Retrieval ...... 45 6.3.2 Token Retrieval ...... 46 6.3.3 Http Module ...... 47 6.3.4 SObjects Module ...... 48

7 Author REST application - conclusion 50 7.1 Introduction ...... 50 7.2 Scheduling the Schedulable classes ...... 50 7.2.1 Requirements ...... 50 7.2.2 CRON expression ...... 50 7.3 Running the job creation script ...... 51 7.4 Scheduled job maintenance ...... 52 7.5 Implementation conclusion ...... 53 7.6 Project conclusion ...... 53

8 Conclusion 54

Bibliography 55

vii List of Tables

viii List of Figures

2.1 Apex code example - example taken from wisdomjobs.com 18 4.1 Authorization process modeled by Jakub Hančin in Signavio modelling software 30 5.1 A screenshot of Deployment settings - sandbox allowance 33 5.2 A screenshot of Object Manager - creation of Custom Objects 35 5.3 A screenshot of the Object Manager - custom field creation 36 5.4 A screenshot of the Developer Console - native development tool of Salesforce opened in Mozilla Firefox browser 38 5.5 A screenshot of The Welkin Suite - 3rd party IDE 38 6.1 SaaScend - LeanTaaS DefHC project structure 41 6.2 An example of a mock String constant and the overriding of a respond() method in a test context. If the respond() method is called with a specific endpoint with specific values in the test context, the body of the response is overwritten with the mockup String contant. 43 6.3 Class interaction diagram created in Lucidchart by Jakub Hančin 44 6.4 Data retrieval main method - performDefinitiveDataPull() 45 6.5 Bearer Token request 46 6.6 Formation of a data request 47 6.7 A snippet of the updateRecords() method. 48 7.1 Script to schedule the integration 51 7.2 Scheduled Jobs interface 52

ix Introduction

Customer Relationship Management systems or better known by their abbreviated phrase CRM are considered useful tools used by numer- ous managers and salespeople across multiple industries. The purpose of this thesis is to introduce CRM platforms and later focus on Salesforce, the CRM market leader of 2019 via an author Salesforce application created for integrating a 3rd party data source into Salesforce.

In chapter 1 we will introduce CRM platforms and explain their relevance in terms of user adoption and market share. We will continue in the chapter 2 with the introduction of Sales- force, the CRM market leader of 2019 and elaborate on the technical and community specifics of this platform. Concluding the theoretical part of the thesis, we will cover potential implementation approaches of 3rd party integrations in the chapter 3. In chapter 4 we will introduce the case study of an author integra- tion which was developed for the LeanTaaS company by Jakub Hančin in the autumn of 2019. We will elaborate the introduction by moving to a required pre- development setup of Salesforce in the chapter 5. Once the objectives of the LeanTaaS project and the pre-requisities of Salesforce development are thoroughly explained we will continue with analysis of the implementation in the chapter 6. After an explanation of the implementation, we will conclude the practical part as well as the whole thesis with post-development requirements of Salesforce and the project conclusion.

1 1 CRM platforms introduction

1.1 What is a CRM

Customer relationship management (CRM) is the combination of best practices, strategies and technologies that companies use to manage and analyze customer interactions and data throughout the customer lifecycle. A CRM platform can be described as a central sales hub system that collects and processes user data. Every user has easy, direct ac- cess to the real-time client data they need. At the most basic level, CRM software allows marketers and salespeople to manage and ana- lyze relationships with the company’s actual and potential customers. It enables tracking every interaction with the company and collects information about the customer. The goal of a CRM platform is to improve customer service rela- tionships, to assist in customer retention, and to drive sales growth[1]. CRM can also be described as providing the functionality to compa- nies across the four segments of customer service and support, digital commerce, marketing, and sales[2]. CRM systems compile customer data throughout various points of contact with the customer and store them in a unified, easy to work with manner on a single platform.

1.2 CRM adoption

CRM platforms are becoming more and more popular. As per the industry estimates, around 91% of companies with over 10 employees have deployed a customer relationship management system in their organization according to a research by Grand View Research[3]. CRM Cloud Survey Report states that the reason for such a large adoption past a certain company size was a need for automating the tracking and reporting of sales and business processes in a central system[4]. The same report claims that around 82% of enterprises use cus- tomer relationship management systems for sales reporting and sales process automation.

2 1. CRM platforms introduction 1.3 CRM platform market

The five main vendors of CRM systems when ranking it by the portion of the CRM market share of 2018 are Salesforce, SAP, Oracle, Adobe and Microsoft. [2]. These five vendors shared 41.2% of the market in 2018 with only Salesforce’s and Adobe’s market share growing faster than the market. While Adobe dominated in the marketing subsegment of CRM (19% for Adobe and 11.7% for Salesforce), all the other subsegments of CRM were dominated by Salesforce. Since 2018, Salesforce grew to 19.5% market share having more than a double of it’s second biggest competitor, SAP (as visible in the included 1.3 graphics).

In 2019, Adobe and Microsoft decided to offer customers a union- ized product of Adobe Experience Manager and Microsoft Dynamics 365 CRM in order to gain a competitive edge against Salesforce and boost the sales and marketing capabilities of both companies. However, there are also a few CRM vendors that offer free CRM so- lutions and as a result, the market share of these companies is nowhere near the subscription-based companies. However, multiple of these smaller players such as Zoho, Hubspot and others form the rest of CRM market and we will talk in the corresponding section about the free possibilities as well.

3 1. CRM platforms introduction 1.4 Economic relevance of the CRM market

In order to understand the importance of the CRM market, it is neces- sary to mention that business expenses related to CRM systems made up close to 25% (48.2 bilion dollars) of the entire enterprise software revenue market in the world in 2018 (193.6 bilion dollars) [5].

According to Grand View Research[3], the global customer rela- tionship management market size was valued at USD 40.2 billion in 2019 and is expected to expand at a compound annual growth rate of 14.2% from 2020 to 2027 (see 1.4). It is also important to mention the return on investment of CRM platforms. According to Nucleus Research, investing in CRM software pays back from $5.60 to $8.71 on average for every dollar spent[6].

4 1. CRM platforms introduction 1.5 Subscription-based CRM platforms

In this section we will introduce various subscription-based CRM plat- forms and the basic pricing of their offers to give a financial overview of the cost of a CRM platform. This section is dedicated to CRM platforms that have no free plan meaning that choosing such a CRM automatically equals financials costs with no possibility of an ongoing free use (many CRM platforms however offer a free 30-day or 14-day trial, but the trial is often too short to responsibly decide whether to stick with a CRM or not).

1.5.1 Salesforce CRM

Salesforce is a company founded in 1999 by Marc Benioff in San Fran- cisco that offers a complete CRM solution for mid-size to large compa- nies with a pricetag that reflects it. Starting at $25 per user per month with high-end prices of $300 per user per month makes it one of the most expensive CRM systems on the market. Salesforce does offer a 30-day trial of Professional edition or a 3 months long Essentials edition trial.

5 1. CRM platforms introduction

Edition Per User Per Month Cost Essentials (up to 5 users) $25 Professional $75 Enterprise $150 Unlimited $300

The details of Salesforce will be discussed further in chapter 2 as Salesforce is the primary topic of this thesis.

1.5.2 SAP CRM

SAP was founded in 1972 in Germany and currently has more than 420 000 customers all over 180 countries and 101 150 employees world- wide focusing on different enterprise software solutions[7] with CRM forming only one of multiple focusing areas. SAP released its first CRM in November 2000 and since then, SAP has consolidated its CRM applications under the terms "Customer Engagement and Commerce" and offers a variety of applications such as Customer Profile Management via SAP Customer Data Cloud, SAP Marketing Cloud, SAP Sales Cloud and many others. SAP CRM starts at $58 per user per month but does not provide any further information about pricing until requested directly from SAP.

6 1. CRM platforms introduction

1.5.3 Oracle CRM

The history of Oracle CRM tracks back to Siebel CRM Systems, a CRM software company founded in 1993 and acquired by Oracle in 2006. Oracle offers On Premises solution where the customer is required to buy or lease infrastructure, including hardware, operating systems and databases, and install a packaged system in its data center. An ap- proach like this was very common in the early 00s and was well suited for companies who needed complete control over the maintenance of their CRM application. Oracle also offers a cloud solution via CRM On Demand, Oracles Sales Cloud or Oracle Engagement Cloud that is paid for by a monthly subscription (the same principle as the majority of CRM vendors). Below is the pricing of Oracle Engagement Cloud, one of Oracle’s cloud tools.

Edition Per User Per Month Cost Professional $65 Standard $100 Enterprise $200 Industry $300

7 1. CRM platforms introduction

1.5.4 Microsoft Dynamics CRM

Microsoft Dynamics CRM development started in 2001 when Mi- crosoft acquired iCommunicate, a 10 employee web based CRM com- pany. In 2003 Microsoft CRM 1.0 was released aiming at small and medium sized businesses offering basic contact and email campaign management. The current version of Dynamics CRM is a server-client application that supports extensive web services interfaces. Clients can access the CRM by using a browser or by a client plug-in. The product focuses mainly on sales, marketing, and service (help desk) sectors, but Microsoft has been encouraging its partners to use the open-source .NET based framework (which was previously proprietary) to customize the platform into a robust CRM platform. Below is the pricing of Microsoft Dynamics 365:

Edition Per User Per Month Cost Sales Professional $65 Sales Enterprise $95 Customer Engagement Plan $115 Microsoft Relationship Sales $130

8 1. CRM platforms introduction 1.6 CRM platforms with a free plan

While the majority of the CRM market share is formed by companies that charge a monthly or annual fee for their services, it is important to also mention vendors that offer free1 CRM systems. However, in the universe of software market, nothing is entirely free and therefore we will include information about pricing of these systems as well. We decided to include the 2 most relevant2 free CRM platforms to provide an economic alternative for anyone interested in trying the added value of a CRM platform without the need of any financial investment.

1.6.1 HubSpot CRM

Hubspot offers a free CRM platform solution that is primarily aimed at small businesses and offers integration features for Salesforce, MS Dynamics and others in case the former small business decides to scale up to a paid solution. Hubspot was founded in 2006 at MIT and quickly grew into a company with $15.6 million in revenue in 2010. In 2019, this number grew to $674.9 million[8] making it one of the most successful CRM vendors (along with Zoho) offering any means of a free plan.

1. Free in terms of a non existing subscription fee for at least 1 user. The revenue is made via additional services that are charged extra. 2. The criteria of the most relevant free CRM in the context of this thesis is simple: We consider relevant any free CRM platform that has more than 1000 user reviews on the G2 group available here to narrow the list. Only 2 platforms matched such criteria.

9 1. CRM platforms introduction

The possibility of having a free CRM platform emerged in 2014 when Hubspot announced the start of Hubspot CRM Free[9] as a re- action to Salesforce’s aquisition of Pardot, HubSpot’s rival. According to HubSpot, the CRM will be free to use forever - even if you’re not a paying HubSpot customer. However, nothing is entirely free in the software industry and Hubspot is no expection. Hubspot’s revenue consists of charging cus- tomers for using the premium features of their software tools and a small portion of its revenue is generated through consulting services and the hosting of events.

1.6.2 Zoho CRM

Zoho CRM is an Indian company founded in 1996 that released the Zoho CMR in 2005. Zoho CRM is only a part of a broader Zoho app ecosystem formed of tools for email marketing, invoicing or case man- agement. Zoho offers a free plan for businesses with less than 10 employees and maximum of 3 users of the CRM. According to TechRadar, Zoho is very easy to use, offers automatic lead creation from social media and provides a lot of integration possibilities. However, a TechRadar reviewer also claims that the pricing plan for larger companies can get too expensive for the value provided, the reporting features are not fully customizable and the customer service is available via email only.[10] Zoho is free for up to 3 users and the pricing for more is as follows:

10 1. CRM platforms introduction

Edition Per User Per Month Cost Up to 3 users $0 Standard $12 Professional $20 Enterprise $35 Ultimate $100

1.7 CRM platforms comparison

It is very hard to compare various CRM platforms because of the huge diversity of the CRM market as well as the different functions each CRM offers. Each CRM platform provides different subset oftheCRM functionality such as Contact Management, Sales Team and Customer Opportunity Management, Lead Management, various Reports and Dashboards, Sales Analytics and the list goes on and on. Some CRM platforms are suited better for large companies that require a complete solution which is indefinitely scalable and cus- tomizable and do not mind the large one-time implementation as well as large running costs. Smaller business may prefer a solution that is less financially demanding in order to answer the starting question of whether they will eventually profit from a more costly CRM platform. The following table contains the market leaders of 2018 mentioned in 1.3 as well as the 2 free CRM vendors mentioned in section 1.6. The table simply describes the entry level price to give a brief overview of the price of CRM platforms ranked by their market percentage of 2019 according to by Datanyze3[11].

3. Datanyze calculates market percentage by taking the number of websites using a technology and dividing it by the total number of websites using any technology in the same category. The number is not equal 1:1 to market share in revenue.

11 1. CRM platforms introduction

Vendor Market Percentage Entry Level Price Salesforce CRM 23.72% $25 /user/month MS Dynamics CRM 4.25% $115/user/month Zoho CRM 4.22% $0/user/month SAP CRM 2.28% $58/user/month Hubspot CRM 0.63% $0/user/month Oracle CRM 0.20% $75/user/month

The CRM market is a very competitive place that can drastically change each year. However, the trends are obvious: on-premises solutions are on decline and more and more companies prefer cloud solutions. The security of the cloud solutions is more robust each year and the main- tenance costs of paying for a cloud solution are nowhere near hosting a proprietary data center or any other proprietary alternative. While Microsoft and Adobe tried to take on Salesforce via forming a union and offering one shared product, Salesforce retains its market leader position despite the efforts. Hubspot is trying to beat Salesforce in terms of financial costs to run a CRM but despite the high running costs of Salesforce, the market share of Salesforce is growing each year. Salesforce has become the equivalent of what Apple represents in the market of mobile phones and in the following chapter, we will try to analyze Salesforce’s technical and community specifics which we believe helped Salesforce maintain its market leader position.

12 2 Salesforce CRM

2.1 History

Salesforce as a company was founded in 1999 by Marc Benioff, a for- mer Oracle vice president in [12] with a goal to de- liver unique sales software through a model known as Software-as-a- Service (SaaS). Salesforce launched its product in 2000 and started to build a whole ecosystem around it to support it. In 2003, first Dreamforce conference took place (see 2.2.2) that evolved throughout the years into a massive 5-day event that attracts attention all over the world. In 2005, Salesforce launched its AppExchange, an application store of Salesforce aps where partners could developer their own applica- tions and Salesforce customers could find whatever they needed. In 2006, Salesforce introduced its own programming language Apex (see 2.3.3 for details about Apex) ant its own java-script frame- work called Visualforce that enlarged the Salesforce ecosystem even more. In 2014, a free learning platform called Trailhead (see 2.2.1) was launched to help anynone learn and build a career in the Salesforce industry.

13 2. Salesforce CRM

In 2015, Salesforce invested into redesigning the Visualforce frame- work that conserved the relatively consistent look of Salesforce for 16 years. The new look was called Lightning experience and its primary purpose was to unify the look of Salesforce across all devices. In 2016 Salesforce invested into a development of its own AI called Salesforce Einstein and enabled to build apps using the Einstein engine behind it. par After 2015, Salesforce started acquiring various smaller corporations to make part of the Ohana1 family. In 2016 alone, Salesforce acquired over 10 companies [12]. In 2018, Salesforce acquired Mulesoft for $6.5 bilion dollars and in 2019 Sales- force topped this acquisition record with acquiring Tableau for $15.7 bilion dollars. In the following two sections, we will describe multiple technical and non-technical aspects of the Salesforce platform that the author be- lieves were a huge contribution to Salesforce’s market leader position of 2019 (see the CRM market graph of 1.3).

2.2 Salesforce - community specifics

In this section, we will look at some of Salesforce’s community specifics that, to the belief of the author, help Salesforce maintain its market leader position by supporting the growth of number of people who are involved in Salesforce’s ecosystem and thus secondarily driving sales of Salesforce licenses.

2.2.1 Trailhead - the Salesforce learning platform Trailhead is a series of online tutorials that coach beginner and inter- mediate developers who need to learn how to code for the Salesforce platform. Trailhead education, which was launched in 2014, comes in three levels: trails, modules and units. Lessons are presented in a specific sequence, so customers have a predefined path to follow and a "guided, curated" experience, according to Salesforce.

1. In 2004, Salesforce started to brand the platform with Hawaiian references such as Ohana which means ’family’ in Hawaiian. Salesforce uses the term Ohana to define the Salesforce community.

14 2. Salesforce CRM

The learning program is designed to help users by providing a series of interactive assessments to identify whether learners have learned the content. Gamification is built into the Trailhead program, so developers can also earn badges for milestones reached in their Trailhead education. [13] Containing more than 700 different modules[14] consisting of multiple exercises to help to learn all that is about Salesforce, the Trail- head learning platform became a reliable learning tool for Salesforce developers when it comes to acquiring new Salesforce skills.

2.2.2 Dreamforce - the Salesforce yearly conference

Another of the community specifics of Salesforce is the organization of an event called Dreamforce. Dreamforce started in 2003 as a regular conference of Salesforce oriented professionals and grew into a global event with 170 000 registered attendees, hosting a concert in 2018[15]. Dreamforce is an annual four-day event that brings the Salesforce community together, including both current and potential clients as well as the companies that help with implementation of Salesforce. It is also open to anyone else from the public interested in any aspect of this CRM. That includes Salesforce professionals such as admins or developers, entrepreneurs on the side of the partners and general managers of various companies on the side of the clients. Formerly this paragraph contained information about the upcom- ing Dreamforce of 2020 and the future of this conference, but when the first draft of this thesis was being completed, Salesforce announced that Dreamforce 2020 will not take place live but only online due to the world-wide pandemic of the coronavirus[16]. While the author of this thesis believes that Salesforce will heavily invest into Dreamforce 2021 in terms of breaking its own records of attendance, the immediate future of this event remains unclear for now (May 2020).

15 2. Salesforce CRM 2.3 Salesforce - technological specifics

In the following section, we will take a closer look at various technol- ogy Salesforce takes advantage of. This includes its own programming language as well as governor limits ensuring the same amount of com- putational power for everyone.

2.3.1 Multitenancy Salesforce is a multi-tenant platform meaning that each all of the so- called ’orgs’ 2 run in the same physical environment and are divided into respectable virtually stand-alone instances. These orgs share the physical resources and in order for each of the tenants3 to have guaranteed storage and CPU, Salesforce enforces strict limits on these resources. Multiple tenants share a hidden, common infrastructure, yet utilize a defined set of highly secure services, with complete privacy from other tenants. In the same manner as a bank client owns a secure private account yet shares the bank security benefits as the other clients, a cloud uses multitenancy technology to share IT resources among multiple applications and tenants that use the cloud[17].

2.3.2 Limits Because Apex runs in a multitenant environment, the Apex runtime engine strictly enforces limits so that runaway Apex code or processes don’t monopolize shared resources. If some Apex code exceeds a limit, the associated governor issues a runtime exception that cannot be handled[18]. Here is a table of few of these limits to provide a hands-on overview of these limits4:

2. Org is a specific Salesforce term used for an environment instance that is virtually separated from others in a same manner as a virtual machine is separated from its host machine. 3. Tenant in this context is a single client who is leasing the computational power of Salesforce. 4. The limit in this context is the synchronous limit as opposed to an asynchronous limit which is less restrictive (but in the context of this thesis redundant for show- casing the nature of the feature)

16 2. Salesforce CRM

Description Limit SOQL queries issued 100 Records retrieved by SOQL queries 50 000 SOSL queries issued 20 DML statements issued 150 Total heap size 6 MB Max CPU time 10 000 ms While these limits may appear too severe and restricting, the en- forcement of these limits guarantees the properties of a true multi- tenant environment that provides the same CPU power, database access speed or database storage to each of the tenants.

2.3.3 Apex - Salesforce programming language It is important to dedicate more space to Apex, the programming language of Salesforce as the whole practical part of this thesis is written in this language. Apex, which is similar to Java in many respects, is a powerful object- oriented development language developed by the Salesforce.com plat- form developers can use to centralize procedural logic in their appli- cation schema. However, there are certain differences between Apex and Java (see this manual page for details). The most important ones are: ∙ The language is case-insensitive5. ∙ The private access modifier is the default, and means that the method or variable is accessible only within the Apex class in which it is defined. ∙ Static methods and variables can only be declared in a top-level class definition, not in an inner class. ∙ An inner class behaves like a static Java inner class, but doesn’t require the static keyword.

5. Many Salesforce developers including the author of this thesis write Apex code as case-sensitive to maintain the Java-like feel and readability of the language.

17 2. Salesforce CRM

Figure 2.1: Apex code example - example taken from wisdomjobs.com

∙ Methods and classes are final by default. ∙ Exception classes must extend either exception or another user- defined exception and the name of every exception must end with the word ’exception’. Apex code can declare program variables and constants, execute traditional flow control statements (if-else, loops, etc.), perform data manipulation operations (insert, update, upsert, delete), and transac- tion control operations (setSavepoint, rollback). With the addition of a simple keyword, developers can use Apex to support many unique application requirements. For example, a developer can expose a method as a custom RESTful or SOAP-based API call, make it asynchronously schedulable, or configure it to process a large operation in batches. Many standard Apex classes and system static methods provide simple interfaces to underlying system features. As an example, the system static DML methods such as insert, update, and delete can be modified by a simple Boolean parameter to indicate the desired bulk processing option (all or nothing, or partial save).

2.3.4 SOQL - Salesforce Object Query Language Salesforce developers can use the Salesforce Object Query Language (SOQL) to construct simple but powerful database queries. Similar to the SELECT command in the Structured Query Language (SQL), SOQL allows a developer to specify the source object, a list of fields to retrieve, and conditions for selecting rows in the source object.

18 2. Salesforce CRM

For example, the following SOQL query returns the value of the Id and Name field for all Account records with a Name equal tothe string ’FI MUNI’.

SELECT Id, Name FROM Account WHERE Name = ’FI MUNI’

2.3.5 SOSL - Salesforce Object Search Lanuage The platform also includes a full-text, multi-lingual search engine that automatically indexes all text-related fields. Applications can leverage this pre-integrated search engine using the Salesforce Object Search Language (SOSL) to perform text searches. Unlike SOQL, which can only query one object at a time, SOSL en- ables the developer to search text, email, and phone fields for multiple objects simultaneously. For example, the following SOSL statement searches for records in the Lead and Contact Salesforce objects that contain the string ’Jakub’ in the name field and returns the name and phone number field from each record found[17].

FIND "Jakub" IN Name Fields RETURNING lead(name, phone), con- tact(name, phone)

19 3 Integrations - implementation approaches

Prior to introducing the Salesforce module app that fulfills the purpose of the data integration, it is necessary to analyze potential approaches to leave no space for possible doubts about the chosen approach.

3.1 Introduction

Whenever a continuous stream of data travels from one point to an- other, three main parts are required. The source, the target and the active component that performs the transfer (this can be either on the side of the source, the side of the target or completely external). Because of the high dynamics of how systems evolve and these evolution require some ongoing maintenance, it is often wiser to keep the amount of components to a bare minimum. Therefore, if possible, it is often better to not use external 3rd party components but rather use either the source or the target as the active component. For the sake of this thesis, we will use two main terms that are widely used in the company of the author, pulling and pushing. Pulling would always mean using the target as the active com- ponent, in this case Salesforce, and pushing would mean using the source as the active component. We will talk about the advantages and disadvantages of both in the upcoming sections. In general, the approaches are equivalent as they depend solely on the technical aspects and attributes of the involved technology, but experience shows that it is crucial to make the right call as the techno- logical capabilities of target and the source may differ significantly. We will try to focus on these approaches with regard to Salesforce and its particular characteristics with regard on obstacles that are often faced when such an integration gets implemented in the real world.

3.2 Pulling

Pulling is a term used to describe a situation where Salesforce acts as the active component of the integration meaning that the code runs

20 3. Integrations - implementation approaches

from within Salesforce and the external server acts solely as a data source that is accessed by Salesforce’s code.

3.2.1 Requirements We assume that anyone choosing pulling is familiar with Salesforce, its programming language Apex (introduced in section 2.3.3) and the structure and configuration requirements (mentioned later in 5). The requirements for successful implementation of a pulling ap- proach are:

∙ Access to the external server (may require credentials and/or configuration)

∙ API for accessing the data

3.2.2 Advantages The main advantage of this approach is that when the active compo- nent is on Salesforce’s side (which will also be the case of the example shown in chapter 4), the developer can take full advantage of the Java- like environment (as described in section 5.4) to program a component able to periodically prompt for new data while respecting various web protocols thus ensuring maximum security. Apex tools enable the developer to easily form and send Http requests, receive Http responses, encode or decode content, schedule the code to run at a certain period or continually work through a large amount of data if the amount is too large to process at once. It is important to note that the mentioned perks are often impos- sible to recreate in the legacy 3rd party systems that in majority of cases play the role of the source (the client would like to cease using the 3rd party system, but that can often prove to be difficult as during the decades all the historical data got accumulated in this old, legacy database).

3.2.3 Disadvantages The obvious disadvantage of ’pulling’ is the large amount of code lo- cated in Salesforce org that may collide with other Salesforce function-

21 3. Integrations - implementation approaches

ality (and often does) such as Process Builders, Workflows, Triggers, etc1. The code also requires to pass the 75% code coverage requirement meaning that in addition to the code development, a developer choos- ing this approach is also obligated to build Salesforce unit tests for the code as well. As if that was not enough, the part responsible for the integration becomes only a one part of the whole colossal Salesforce system the client has and as a result of incomplete overview of the system, the client may eventually put contradictory rules into place (an example: Never allow a record to be saved without an attribute X but the at- tribute X is not included in the integration of the 3rd party database) that may compromise smooth execution of the code. Another disadvantage (from the point of the view of the client) is that there is a huge probability that the client is not as familiar with Salesforce as he is with the 3rd party application (often the application is developed directly by the client). This is not surprising as if the client was familiar with Salesforce, he would not require a dedicated Salesforce developer to help him with such an integration in the first place.

3.3 Pushing

The term ’pushing’ stands for the opposite of ’pulling’ which in this context means that Salesforce takes the role of a passive listener and the external server or 3rd party takes the role of an active component that forms requests.

3.3.1 Requirements Even though the pushing alternative has more challenging require- ments it may be the way to go for anyone who prefers to develop outside the Salesforce’s ecosystem (after fiddling with the configura- tion of the Salesforce org first to allow such integration to run).

1. Process Builders and other mentioned tools are easy to set up Salesforce Admin components that often have the same level of access as the developed code which may cause severe collisions when such components pose restrictions on database operations. 22 3. Integrations - implementation approaches

The requirements for a successful pushing alternative are as fol- lows[19]: ∙ Create a Salesforce developer account ∙ Set up a Connected App – Choose App Name - can be anything like ’TestApp1’ – Enable OAuth Settings – Specify Callback URL - any secure webpage where you want the data to be sent afterwards – Choose OAuth Scopes - Access and manage your data (API) Once the setup of the App is done, Salesforce will redirect you to the details of the App from where you can access the Consumer Key and the Consumer Secret required in the app later when communicat- ing with Salesforce. You can also choose to generate an initial Access Token that will be later used for accessing data or leave the token generation for later.

3.3.2 Advantages The advantage number one of this approach is the independence from Salesforce (if that is the objective). Salesforce acts as a listener that waits for instructions from your external server and will take no action other than those that you sent through the Connected App. You can also easily turn the integration off from your own envi- ronment by turning off the Connected App or by simply stopping sending requests to Salesforce.

3.3.3 Disadvantages The obvious disadvantage is the complex configuration one needs to complete prior to development as well as the need to fully understand the data and security flow of the Connected App mechanism. Salesforce enforces heavy security on any communication coming through and this may turn out to be too much time consuming to overcome and therefore not economic to pursue.

23 3. Integrations - implementation approaches 3.4 Conclusion

It is hard to decide with certainty whether it is more costly to hire a Salesforce developer to develop the pulling functionality or go for pushing variant and simply hire a Salesforce consultant to help with the configuration of the Connected App and do the rest of the devel- opment externally. Both approaches lay out specific challenges to overcome as well as responsibilities to bear in mind and each project or client may require different approach depending on client’s needs, internal development team and finances. As the author of the thesis specializes in Salesforce development in Apex, we will present a case of a project that took advantage of the pulling appraoch.

24 4 Author REST application - case study

4.1 Introduction

In this chapter an author application is about to be introduced that sums up the theoretical knowledge introduced above into a concrete piece of code.

4.1.1 Context Jakub Hančin, the author of this thesis is a professional Salesforce developer (certified as Platform Developer I) working for a San Fran- cisco based company called SaaScend which specializes in helping companies adopt Salesforce as their CRM. This adoption includes administration as well as development work is aimed at making Salesforce the primary sales hub o the com- pany. The development work often includes the integration of 3rd party applications of which one was chosen to serve as an example for the practical part of this thesis.

4.1.2 Project context In June 2019, LeanTaaS company paid Saascend - a Salesforce consul- tancy company to provide help with migration to Salesforce which LeanTaaS recently made a decision to move their agenda to. The project consisted of multiple objectives such as internal Sales- force customizations, Hubspot1 integration, Outreach2 implementa- tion and other custom features. One of the objectives was to integrate data from the source database of Definitive into Salesforce. This task was given to the author ofthis thesis, Jakub Hančin with the supervision of Craig Jordan, the owner of SaaScend and seasoned Salesforce admin.

1. HubSpot offers a platform of marketing, sales, customer service, and CRM software - we could consider it a Salesforce competitor of sorts. 2. Outreach is a sales engagement platform that allegedly ’helps efficiently and effectively engage prospects to drive more pipeline and close more deals’.

25 4. Author REST application - case study

4.1.3 Description of the objective ?? The goal of the integration was to provide a company called Lean- TaaS a solution that would mirror the contents of a database of hospi- tals and related agenda into Salesforce. The data was stored in a database managed by a company called Definitive Healthcare with a publicly shared API (available here) and thorough documentation on how to access the data. The data format used on the server side was traditional JSON and the desired entities to integrate were Hospitals that were to be synchronized as Account objects in Salesforce and News Items that would get a new custom object in the Salesforce system.

4.1.4 Project - team & pre-project analysis While the whole project contained more SaaScend members, the Defini- tive integration fragment relevant to this thesis consisted of:

∙ Jakub Hančin (SaaScend) - Salesforce developer

∙ Craig Jordan (SaaScend) - project supervisor

∙ Allie Fahner (SaaScend) - project communicator

∙ Joseph Belotti (Definitive) - Definitive engineer

While the whole Definitive integration (in terms of the case study of this thesis) was written by the author of this thesis himself, the results were tested, examined and validated by Craig Jordan to provide feedback. Another member of SaaScend, Allie Fahner helped with the communication and client facing during the project. Joseph Belotti from Definitive helped with forming a sample query for the Definitive server and later John helped with validating specific queries required for successful continuous data integration on the Definitive Healthcare side. The initial analysis showed no unusual obstacles and therefore the initial educated guess on the amount of hours for the project was roughly estimated to 60-70 hours of development work.

26 4. Author REST application - case study 4.2 Obstacles to overcome

As every integration project this one as well was all about anticipating and overcoming obstacles. Prior to the start of the development, the client requested an educated guess on the number of hours for the project. To provide that, an analysis of the obstacles was made. Those obstacles included mutual inconsistency of data format of the source and the target, secure authentication & authorization and various transformations that are sure to be required but remain un- known upfront. We will discuss these obstacles in detail and propose a potential solution that is to be explained in a detailed and more technical manner in the chapter 6.

4.2.1 Data heterogeneity

It was expected that the source and the target data values will differ as well as it wass expected that the potential mistakes of storing data inconsistently will not be carried over from the legacy source database to the target. E.g. a datetime field format in the source database may notbe compatible with the datetime format of the target or a value that even though represents a numeric value may be stored as a String in the source database while the client wants to store it as a numeric value on the target side.

4.2.1.1 Solution

The solution to this difference in the structure of the returned data was simple. Programatically reformat each entry to the desired format based on the previous analysis of a returned sample data-set. As the target is Salesforce CRM, this can be easily done via Apex in the very same manner as this can be done in Java language or per se in any other programming language adjusted to working with an array of alphabetical characters or better known as a String class.

27 4. Author REST application - case study

4.2.2 URL encoding query requirement

For protocol reasons, it was required in order for a query to be valid to encode the query in URL encoded format that is sometimes referred to as percent encoding. The URL encoding is rather simple. URLs can only be sent over the Internet using the ASCII character-set. Since URLs often contain characters outside the ASCII set, the URL has to be converted into a valid ASCII format. URL encoding replaces unsafe ASCII characters with a "%" followed by two hexadecimal digits[20].

4.2.2.1 Solution

The solution to this obstacle was rather trivial. It was required to write a simple parsing function (the set of native static Apex classes do not provide this) that would translate a string of characters into a URL encoded format thus replacing certain reserved characters with appropriate symbols. For the purposes of this integration, two simple character replace- ments sufficed to get rid of the problem.

∙ Each space character ’ ’ is replaced with ’%20’

∙ Each double quote character ’"’ is replaced with ’%22’.

4.2.3 Periodicity

The client requested to perform daily updates of the Definitive Health- care database in order to keep the CRM database up to date. More frequent updates were not necessary as the source database got up- dated once per day as well.

4.2.3.1 Solution

Salesforce by default offers Apex solutions to provide such functional- ity, therefore this requirement can be easily met.

28 4. Author REST application - case study

4.2.4 Authorization The standard obstacle of integrating multiple systems together is over- coming authorization. The authorization is always a little different for each project, but the principles stay the same. Include the credentials, get authorized and get provided the requested data. In the case of the LeanTaaS project, the approach was quite simple (as mentioned at https://api.defhc.com/v4/Documentation): Query with the credentials via a POST request for an access token that would authorize the following data requests. The token is used in all following requests as an authorization element. The token, however, expires in 86,399 seconds (which equals 23 hours 59 hours 59 minutes). Once the request containing a valid access token and correctly formed query was sent, the server returned a JSON document con- taining the requested data. If the token was invalid or expired, the server returned an authorization error message. The flow could be summarized as follows (for more details see 4.1):

1. The client requests the access bearer token from the server with client credentials. 2. If the credentials are valid, the server returns a valid access token valid for 24 hours. 3. The client requests data with the access token. 4. If the token is valid and the query is well formed, server returns the desired data.

4.2.4.1 Solution Salesforce allows the developer to store essential configuration items such as access tokens in an object called Static Resource. However, these objects cannot be created from within the platform programmatically without the usage of a callout via METADATA API (these are the restrictions of the platform) [21]. In order to use Static Resource object for this, one would need to download the METADATA API package (available here) and include the 2MB of data in the same folder where your custom code is or go through the downloaded code

29 4. Author REST application - case study

Figure 4.1: Authorization process modeled by Jakub Hančin in Sig- navio modelling software

30 4. Author REST application - case study

and delete everything obsolete which is time consuming and not a trivial task. For these reasons, it was decided to not go through with the option of a Static Resource approach. Another option to accomplish the same result is to create an in- stance of an object called Custom Setting. Custom setting is an internal object used frequently to store custom configuration information. The object is able to store multiple custom String fields of maximum length 255. As it was previously tested that the access token is never longer than 512 characters, the author of this thesis decided to create 3 custom fields of length 255 in the custom object of the Custom Setting type (the longest case of an access token would sum up to 255 + 255 + 2). While it may seem odd to solve such a problem in this manner, the approach proved to be the most simple one and sufficed to complete the objective.

31 5 Author REST application - pre-development setup

The next step once the theoretical analysis of the problem was done was the setup of the Salesforce org for development of the integration. There were multiple configuration actions that were needed tobe done prior to starting of the development itself.

5.1 Sandbox - testing environment

The obstacle number one Salesforce created for proper development process was the fact that no code can developed on the Production org (for a definition of an ’org’ see section 2.3.1). For development and other testing purposes one needs to clone the Production org into a special development org called Sandbox (the similarity between the chosen name and a children playground is not coincidental). Depending on the license of the client, the sandbox can be of mul- tiple types [22], the most important differences are as follows:

Storage Data copy Developer 200MB Metadata only Developer Pro 1GB Metadata only Partial Copy 5GB Sample of data + Metadata Full Copy equal to production All data + Metadata

5.1.1 Configuration

Once the sandbox was created it was required to enable the specific sandbox to upload its change sets directly to production. This can be easily done (but it is often forgotten and therefore important to stress out) from Setup -> Deployment Settings as visible in the screenshot of 5.1.

32 5. Author REST application - pre-development setup

Figure 5.1: A screenshot of Deployment settings - sandbox allowance

5.1.2 Change set - uploading changes from a sandbox to production

Once the functionality is developed in the sandbox and the sandbox is allowed to make inbound changes, it can get uploaded into production where the validation process begins. Once uploaded, the changed functionality has to pass successful testing (unit tests need to be developed along the core functionality). In order for the code to be validated, the code needs to have at least 75% code coverage by the unit tests. Then and only then can be the code deployed to production. Scripts such as the one written in 7.1 that are part of Anonymous windows do not count as deployed code. This approach tries to prevent incomplete or poorly written code from affecting the production.

33 5. Author REST application - pre-development setup 5.2 Org preparation

As mentioned in 4.2.4.1, multiple customization of the org where the development takes places are needed prior to writing the code itself. This includes the creation of new objects and fields as well as minor configuration changes.

5.2.1 Custom object creation

When a client desires to map any of the external objects to Salesforce, the first course of action any seasoned Salesforce developer should take is to try to map such an object to an already existing Salesforce object. In our case, we discovered that the client’s data revolved around hospitals where Hospitals were the crucial object everything was involved in. For such reason, it was decided to map the Hospitals records to Accounts and create custom Salesforce fields for the fields that are not present by default (see subsection 5.2.2 on creation of custom fields). However, for objects that do not have a Salesforce equivalent or have their Salesforce equivalent already taken by an another external object, it may be wise to consider creating brand new custom objects that would store the information. This can be easily accomplished from Setup -> Object Manager in Salesforce as visible in the screenshot of 5.2. As mentioned in the subsection ??, it was decided to map Hospitals to Accounts (native Salesforce object) and News Items to a brand new custom object of the same name. These custom objects have a special namespace suffix ’__c’ differ- entiating them from native Salesforce objects. It is for this reason that the brand new custom object was be called NewsItems__c. An alternative to that would be News_Items__c but it was decided to omit spaces in a similar manner as Salesforce does for simplicity (e.g. CampaignInfluence objects or OpportunityContactRole objects omit spaces instead of replacing them with an underscore).

34 5. Author REST application - pre-development setup

Figure 5.2: A screenshot of Object Manager - creation of Custom Ob- jects

5.2.2 Custom field creation

Once the objects are in place (whether custom or native), it is required to create (if need be, each project may be different) custom fields which would be storing the actual values in their respectable data type. This is again easily done via Setup -> Object Manager as seen in the screenshot of 5.3. Same as for custom objects, custom fields have the ’__c’ suffix mean- ing that a custom field of HospitalId that was named ’defin_HospitalId’ would in reality be stored as ’defin_HospitalId__c’.

35 5. Author REST application - pre-development setup

Figure 5.3: A screenshot of the Object Manager - custom field creation

Numerous projects require the creation of multiple custom fields, often close to a hundred and in those cases, manual creation may turn out rather time consuming. For such cases, it is preferred to create the fields programatically and while this cannot be done as easily as the manual creation, tools like Salesforce Command Line1 are very suitable for such a task. As the automated creation of custom fields was not the main obstacle of the case study and the description of the process is not a trivial task, we will leave such a possibility unexplored in this thesis.

1. On such an occasion I would like to dedicate this space to Aleš Remta, a former colleague of mine who introduced me to Salesforce CLI and who by doing so saved a lot of my time and patience.

36 5. Author REST application - pre-development setup 5.3 Suitable IDE

In order to developer in the Salesforce platform, it is required to either develop the functionality in the native tool of Salesforce called Devel- oper console (which would be strongly dissuaded by the author of this thesis) or use a 3rd party IDE. The following sections may contain a slightly biased opinion of the author of this thesis.

5.3.1 Developer console - native Salesforce tool

The Developer console provides all the necessary functionality of development inside the browser and is very suitable for minor changes in code or for running scripts in an Anonymous window. However non-programmer users as well as developers find this tool less convenient than any other means of development.

5.3.2 The Welkin Suite - external IDE based on VisualStudio

The alternative to developing in the native tool of Salesforce is to choose a 3rd party IDE. There are multiple viable options on the market and there is no other reason than convenience and the resemblance to VisualStudio why The Welkin Suite was chosen for this thesis (screenshots of this IDE are used in the chapter 6). If one chooses to develop in a 3rd party tool, it is required to provide the login information, the password and a security token which a case-sensitive sequence of characters (the Developer Console does not require this as it is an internal part of the Salesforce org).

37 5. Author REST application - pre-development setup

Figure 5.4: A screenshot of the Developer Console - native develop- ment tool of Salesforce opened in Mozilla Firefox browser

38

Figure 5.5: A screenshot of The Welkin Suite - 3rd party IDE 6 Author REST application - implementation

6.1 Introduction

With regard to the previous requirements of the project as well as with regard to Salesforce’s platform requirements and restrictions, we have created a simple module in within LeanTaaS’s org that downloads the requested data each day and stores it in Salesforce objects as requested.

6.1.1 Overview of the functionality The integration module was set to perform these actions and repeat the procedure every 24 hours:

1. Request and get a new access token (valid for 24 hours).

2. Use the token to download and store most recent data related to Hospitals.

3. Use the token to download and store most recent data related to News Items.

6.1.2 Restrictions in possible recreation As the application is a custom developed internal part of a licensed software that is a propriety of the client, the application is not a stan- dalone solitaire possible to run without the action of mounting to a dedicated Salesforce org. Nonetheless, a skilled developer and as the author of this thesis believes, anyone taking the time to read this thesis should have no trou- ble adjusting the provided source code with minimal effort to recreate another functional instance of a JSON -> Salesforce integration.

6.1.3 Structure of code analysis We will analyze the crucial parts of the project and the approach how the major functions interact with each other. Minor or trivial functions covering functionalities like CRUD operations or data formatting will

39 6. Author REST application - implementation

be left theoretically uncovered but accessible to any curious eyes in the source code located in the attachment. To comment on the source code in a comfortable and readable way, we will use screenshots of the Welkin Suite IDE to easily distinguish between the code and the written part of the thesis. The source code of the project is available in its full length in the attachment of this thesis in the form of .cls files that can be easily read in any modern IDE. More detailed analysis of the the approaches used as well as com- plete commentary on each and every method used is as already men- tioned above available as a commented block in each respectable class.

6.2 Project structure

The project consists of 7+1 classes as seen in the graphics of 6.1 where 7 classes form the backbone of the application that takes advantage of the native functionality of the Salesforce platform and 1 extra test class handles unit testing.

6.2.1 Integration functionality - code hierarchy There are 2 main classes:

∙ Data retrieval - handles the top level of requesting and storing data

∙ Token retrieval - handles token requesting.

The 2 main classes use the 3 helping modules where each module is responsible for a certain technological aspect:

∙ Http module - handles the Http requests and responses, their proper formation for a given cause and their sending process.

∙ Parsing module - provides various transformation methods for each of the 4 classes above. This includes HTTP response transformation into objects, JSON processing, URL encoding and others.

40 6. Author REST application - implementation

Figure 6.1: SaaScend - LeanTaaS DefHC project structure

∙ SObjects module - module handles inserts and updates of the data into Salesforce objects with regard on Salesforce restric- tions. The functionality of the 2 main classes is used by 2 schedulable classes that provide means for the developer to set up a periodical execution: ∙ Data schedulable - encapsulates the Data retrieval class func- tionality with Schedulable interface ∙ Token schedulable - encapsulates the Token retrieval class functionality with Schedulable interface An oversimplified class interaction diagram available at 6.3 was created to make it easier for the reader to understand how these classes interact with each other (the Parsing module was omitted to keep the diagram readable).

41 6. Author REST application - implementation

6.2.2 Test class - mandatory unit tests The included test class contains all the necessary unit tests to pass Salesforce’s rule of minimum 75% code coverage1 To be able to a functionality working with a potentially unstable external response2 a special approach is chosen. The test class, when running in a test environment, is given a ’mock’ response that contains a snippet of the actual data. This can be easily done by the setMock() method which, in the test conditions, overwrites the behavior of the standard respond() method and returns the pre-planned response. The response can even return different mock response based of different request attributes (such as the endpoint or method ofthe request). For the purposes of this project, we have created 3 mock String constants to possibly simulate a simplified behavior of the Definitive server. 2 constants for a mock response of Hospitals and News Items and 1 response for an example of an access token. The 2 data mocks were manually created from a valid server re- sponse by erasing everything but 4 records chosen at random in each of the responses. This was required to be done because of the initial size of the response that exceeded the possible String length3. The 1 access token mock was created from an old invalid token to simply test the access token storage functionality. A demonstration of how the mentioned test functionality is written is present in the 6.2 figure.

1. As already mentioned in 3.2.3, Salesforce does not allow any code to be deployed to production without being at least 75% covered by a test class. 2. The test cannot rely on the homogenity of the Http response. The server can stop working, the server can be reconfigured or the network can be unstable and the test needs to be independent of such circumstances. 3. In compliance with the Occam’s razor we did not want to complicate the process by storing the whole response as a Custom Setting which may had turned out to be impossible in the test context.

42 6. Author REST application - implementation

Figure 6.2: An example of a mock String constant and the overriding of a respond() method in a test context. If the respond() method is called with a specific endpoint with specific values in the test context, the body of the response is overwritten with the mockup String contant.

43 6. Author REST application - implementation 6.3 Code Analysis

In this section we will provide a top-level analysis of the code that is part of this thesis and available in the attachment. The Parsing module section is omitted as this module contains only trivial self-explanatory methods.

Figure 6.3: Class interaction diagram created in Lucidchart by Jakub Hančin

44 6. Author REST application - implementation

6.3.1 Data Retrieval The backbone of the functionality contains one single method - per- formDefinitiveDataPull(). This method uses nearly all of the developed functionality present in other modules in some way therefore an in depth analysis would be redundant as we are going to cover the rest of the modules below.

Figure 6.4: Data retrieval main method - performDefinitiveDataPull()

The top level flow of the method is as follows: 1. Get a valid token from the Salesforce database. If there is none, refresh the token and stop4.

4. Salesforce restricts a scenario of Callout - DML operation - Calllout from hap- pening. Requesting a 3rd party for a token is considered a callout and storing it is considered a database operation therefore a subsequent data request is restricted.

45 6. Author REST application - implementation

2. Form a request for the data with the access token.

3. Process the response into a Set of Maps of the type Map.

4. Update the Salesforce objects based on the processed data.

6.3.2 Token Retrieval The Token Retrieval class contains multiple methods that process the token (the most tricky part is the division into thirds that is explained in 4.2.4.1). The screenshot of 6.5 explains in detail how the processing of the Http response works. The visualized method refreshDefinitiveBear- erToken() corresponds to the following steps 2 to 4. The top level flow of the method is as follows.

1. Try to get an access token from the Salesforce database.

2. If there is not a valid one, form an Http request using creden- tials and obtain a response.

3. Process the response into a JSON.

4. Process the JSON into an access token.

5. Store the token.

Figure 6.5: Bearer Token request

46 6. Author REST application - implementation

6.3.3 Http Module The Http Module is responsible for formation and sending of Http requests and responses. Even though the details are trivial, it is still important to mention how simple and easy it is to form an Http request within a modern object-oriented language environment such as Java (or Java-like Apex in this case) as seen in 6.6. It is only required to set a method, multiple optional headers, set the body and send the request. The only challenging step is the transformation of a String with restricted characters into a URL-encoded format which may not be provided out-of-the box by the programming framework. The additional parameters seen in the graphics reference the ac- cess token, the entityType which is in our case either ’Hospitals’ or ’NewsItems’ and conditions which specify the date range interval of the desired request.

Figure 6.6: Formation of a data request

47 6. Author REST application - implementation

6.3.4 SObjects Module The following module is responsible for updating the Salesforce objects with provided information. While the majority of this module is trivial in terms of simply replacing values A with values B there is a certain pattern in place that is worth mentioning.

Figure 6.7: A snippet of the updateRecords() method.

Due to the fact that Salesforce enforces various limits and one of those limits is the DML limit meaning database access attempts, it is important to optimize the functionality accordingly. This is nothing but logical as any beginner’s database course teaches that databases are built in such a way that they are large but slow and any action of accessing records is much more expensive than an inter- nal memory action.

48 6. Author REST application - implementation

As our example (and possibly the majority of real-world cases) tries to process a Http response containing hundreds of records, it would be inefficient to update such records in a simple for cycleas such an approach would trigger a number of DML calls equivalent to number of records. To minimize the number of database accesses a following approach was chosen (as visible in the snapshot of 6.7). We assume that we already got a data response from the Definitive server and parsed it into a set of maps:

1. Process the response into a set of IDs.

2. Request only those records from the Salesforce database that have one of the IDs to update later.

3. Process the response again into records and update the set from the step 2 with new information.

4. Upsert the set of records into database.

49 7 Author REST application - conclusion

7.1 Introduction

Now that the code is properly put in place it is required to schedule the code for continuous execution from within the Salesforce interface.

7.2 Scheduling the Schedulable classes

In order to benefit from the functionality developed in chapter 6,it is required to create a Scheduled job in within Salesforce that would run the main methods(the performDefinitiveDataPull() from the Data Retrieval class and the obtainAndPotentiallyRefreshToken() from the Token Retrieval class).

7.2.1 Requirements To create the job, one needs to run a simple script specifying 3 values:

∙ The name of the job - can be anything one sees fit like ’MyMid- nightScheduledJob’

∙ The frequency of the execution - requires a CRON expression further explained in 7.2.2

∙ The schedulable class to execute - for example new ssnd_DefinitivePull_DataSchedulable()

7.2.2 CRON expression The software utility cron is a time-based job scheduler in Unix-like computer operating systems that is used as well in specifying the frequency of scheduled jobs in Salesforce. Even though the formation a valid CRON expression may become tricky for complicated cases, for our purpose it will suffice to simply understand the most basic examples. A CRON expression is a string consisting of six or seven subexpres- sions (fields) that describe individual details of the schedule. These

50 7. Author REST application - conclusion

fields, separated by white space, can contain any of the allowed values with various combinations of the allowed characters for that field.[23] Let us state few examples to demonstrate how can such CRON expressions look:

Expression Description ****** Run every second 0 15 10 ? * * Run at 10:15 a.m. every day 0 11 11 11 11 ? Run every November 11 at 11:11 a.m. There are even CRON expression generators available on the in- ternet (for example this one ) that take care of the CRON expression formation for you.

7.3 Running the job creation script

In order to schedule the integration to run periodically, we need to run a script specifying the information mentioned above in 7.2.1. To do so, we need to run the script via an Anonymous Apex win- dow and schedule 2 jobs (one for token refreshing and one for data pulling) with the System.schedule() method. It is important to state that the data retrieval method depends on an already downloaded valid access token and for that reason the execution of the data retrieval method is delayed in the script by one minute after the token retrieval method. This can be easily done via the Developer console in Salesforce or by creating an Anonymous window directly in your IDE. Such a script could look like this:

Figure 7.1: Script to schedule the integration

51 7. Author REST application - conclusion 7.4 Scheduled job maintenance

Such a scheduled job can be easily terminated from within the user interface via Setup -> Environments - > Jobs -> Scheduled Jobs. The list contains all the Scheduled jobs present in the org without the exception of the 2 jobs specified earlier in 7.3 as visible in 7.2.

Figure 7.2: Scheduled Jobs interface

52 7. Author REST application - conclusion 7.5 Implementation conclusion

With the running of the mentioned script the work on this part of the project is done and the code is set for continuous execution. According to the script (see 7.1), each day at 00:30 an access token is downloaded from Definitive and 1 minute later at 00:31 the data is pulled fromthe server. This action concludes the set of actions required to deploy such a custom integration to Salesforce and doing so finishes the development part of the project.

7.6 Project conclusion

The project started in June 2019 and contained multiple objectives where the integration mentioned and described in this thesis was only one of the multiple objectives. The integration part started in November 2019 by setting up the goals and by including the author of this thesis. The project was finished on the 8th of January 2020 once the docu- mentation was handed over to LeanTaaS and the integration runs to this day on the org of LeanTaaS. The part of the project that is described in this thesis took 73.25 hours to complete including communication calls, upfront API analy- sis as well as the development itself. For tracking the number of hours spent, cloud software Toggl was used. The completion of various tasks was tracked in Asana, a cloud task-tracking software and the devel- opment was done in The Wekin Suite IDE, an IDE based on Visual Studio that was already mentioned in the practical part of the thesis. Based on the work of SaaScend (the part that is described in this the- sis as well as others), LeanTaaS is negotiating with SaaScend about the potential takeover of the whole Definitive server and its maintenance as Definitive server serves as the primary data source of LeanTaaS.

53 8 Conclusion

The purpose of this thesis was to introduce the concept of CRM plat- forms with focus on Salesforce, the CRM market leader of 2019. First, we introduced CRM platforms in general, reviewed the his- tory of CRM platforms and summarized the CRM market situation of 2018 and 2019. Then we focused on Salesforce, the market leader of 2019 and its technical specifics such as its own programming language Apex or query language SOQL that one needs to be aware of prior to starting any advanced development on this platform. We continued with a brief summary of integration aproaches, au- thentication and authorization measures required to successfully con- nect a 3rd party application with a client Salesforce instance. Once the theoretical part was concluded, we presented a real- world case study of a company called LeanTaaS that hired the author of this thesis at the end of 2019 to build an application integrating 3rd party data source. The application was supposed to pull data from an external server and transform the JSON data into Salesforce objects. The case study was then elevated into an implementation of the ap- plication containing all the necessary steps for a successful deployment including the pre-development stages, configuration setup, develop- ment itself as well as post-development unit testing. Result of the implementation is daily used by LeanTaaS and the code (omitting only the credentials of the client) is available in the attachment of the thesis.

54 Bibliography

1. ROUSE, Margaret. CRM (customer relationship management) [on- line]. ComputerWorld, 2019 [visited on 2020-03-30]. Available from: https://searchcustomerexperience.techtarget.com/ definition/CRM-customer-relationship-management. 2. COLUMBUS, Louis. Salesforce Now Has Over 19% Of The CRM Market [online]. Forbes, 2019 [visited on 2020-03-30]. Available from: https://www.forbes.com/sites/louiscolumbus/2019/ 06/22/salesforce-now-has-over-19-of-the-crm-market/ #22524158333a. 3. Customer Relationship Management Market Size, Share & Trends Analysis Report By Solution, By Deployment, By Enterprise Size, By End Use, By Region, And Segment Forecasts, 2020 - 2027 [on- line]. Grand View Research, 2020 [visited on 2020-05-06]. Avail- able from: https://www.grandviewresearch.com/industry- analysis/customer-relationship-management-crm-market. 4. FY’16 CRM Cloud Survey Repor [online]. SoftClouds, 2016 [visited on 2020-05-06]. Available from: https://softclouds.com/wp- content/uploads/2016/09/CRM-Cloud-Survey-Report.pdf. 5. MOORE, Susan. Gartner Says Worldwide Customer Experience and Relationship Management Software Market Grew 15.6% in 2018 [online]. Gartner, 2019 [visited on 2020-04-01]. Available from: https : / / www . forbes . com / sites / louiscolumbus / 2019/06/22/salesforce- now- has- over- 19- of- the- crm- market/#22524158333a. 6. CRM pays back $8.71 for every dollar spent [online]. Nucleus Re- search, 2014 [visited on 2020-05-06]. Available from: https:// nucleusresearch.com/research/single/crm-pays-back-8- 71-for-every-dollar-spent/. 7. SAP: The World’s Largest Provider of Enterprise Application Software [online]. SAP [visited on 2020-05-16]. Available from: https: //www.sap.com/documents/2017/04/4666ecdd- b67c- 0010- 82c7-eda71af511fa.html.

55 BIBLIOGRAPHY

8. FLANAGAN, Ellie. HubSpot Reports Q4 and Full Year 2019 Results [online]. 2020 [visited on 2020-05-16]. Available from: https: //www.hubspot.com/company-news/hubspot-reports-q4-and- full-year-2019-results. 9. SALAGER, Serge. The Effect Of HubSpot’s CRM Launch On Sales- force [online]. 2014 [visited on 2020-05-16]. Available from: https: //techcrunch.com/2014/12/10/is-hubspots-crm-launch-a- declaration-of-war-to-salesforce/. 10. GRAW, Michael. Zoho CRM review [online]. 2015 [visited on 2020- 05-16]. Available from: https://www.techradar.com/reviews/ zoho-crm. 11. Market Share Category : Customer Relationship Management [online] [visited on 2020-05-16]. Available from: https://www.datanyze. com / market - share / customer - relationship - management -- 33/microsoft-dynamics-crm-market-share. 12. CAREY, Scott. A brief history of Salesforce.com [online]. Comput- erWorld, 2018 [visited on 2020-03-23]. Available from: https:// www.computerworld.com/article/3427741/a-brief-history- of-salesforce-com.html. 13. MARGARET ROUSE, Lauren Horwitz. Salesforce Trailhead [online]. 2016 [visited on 2020-05-01]. Available from: https: //searchcustomerexperience.techtarget.com/definition/ Salesforce-Trailhead. 14. Modules: dive into specific topics [online]. Salesforce [visited on 2020-05-03]. Available from: https://trailhead.salesforce. com/en/modules. 15. Metallica Brings Fans Even Closer with Salesforce [online]. Sales- force [visited on 2020-05-01]. Available from: https : / / www . salesforce.com/company/news-press/press-releases/2018/ 09/180925-0/. 16. Breaking News: Dreamforce 2020 will be Virtual for the First Time [online]. SalesforceBen, 2020 [visited on 2020-05-01]. Available from: https : / / www . salesforceben . com / breaking - news - dreamforce-2020-will-be-virtual-for-the-first-time/.

56 BIBLIOGRAPHY

17. The Force.com Multitenant Architecture [online]. Salesforce, 2016 [visited on 2020-05-01]. Available from: https://developer. salesforce.com/page/Multi_Tenant_Architecture. 18. Execution Governors and Limits [online]. Salesforce [visited on 2020-05-01]. Available from: https://developer.salesforce. com/docs/atlas.en-us.apexcode.meta/apexcode/apex_gov_ limits.htm. 19. VAUGHAN, Russell. How to build a basic Salesforce REST API Integration [online]. 2018 [visited on 2020-04-29]. Available from: https://www.gosquared.com/blog/salesforce- rest- api- integration. 20. T. BERNERS-LEE R. Fielding, L. Masinter. Uniform Resource Iden- tifier (URI): Generic Syntax [online]. 2005 [visited on 2020-04-03]. Available from: https://tools.ietf.org/html/rfc3986. 21. BANGAD, Amit. Create static resource with apex code [on- line]. 2015 [visited on 2020-04-05]. Available from: https : //salesforce.stackexchange.com/questions/88182/create- static-resource-with-apex-code. 22. Salesforce Sandbox Environment Types [online] [visited on 2020- 04-27]. Available from: https://www.flosum.com/salesforce- sandbox-environment-types/. 23. VIXIE, Paul. Linux man page [online]. 1999 [visited on 2020-04-26]. Available from: https://linux.die.net/man/5/crontab.

57