integrations – from startpoint to endpoint...visual of the interacting parts. martin fowler’s...

13
Integrations – From StartPoint to EndPoint Terry Luschen Software Engineer marketing + technology 701.235.5525 | 888.9.sundog | fax: 701.235.8941 2000 44th st s | floor 6 | fargo, nd 58103 www.sundoginteractive.com

Upload: others

Post on 29-Mar-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint

Terry Luschen Software Engineer

marketing + technology

701.235.5525 | 888.9.sundog | fax: 701.235.89412000 44th st s | floor 6 | fargo, nd 58103www.sundoginteractive.com

Page 2: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

2

systems usually cannot be removed from the business processes as they have become integral to the function of that business. To understand how existing business processes will interact with newly integrated systems like Salesforce takes a detailed understanding of the existing system plus a big-picture vision of the new system. To build a detailed view of the current state to the finished system will take many key stakeholders. These stakeholders will include, but are not limited to:1. Business Leaders – They understand how the current

business processes function.2. Current Information Technology Workers – They

understand the data, where it resides and how it is reported upon.

3. Future Business Owners of the New System – This can be the same as the current business leaders, but it will usually be a subset of those users. These individuals must immerse themselves in understanding how the new integrated system must function.

4. Future Information Technology Workers – They understand how to best move data to the new system and how the data will most efficiently reside in the new system.

5. All of these stakeholders must be in continuous communication about the state of the project and keep an eye on the dependencies that exist.

Structuring the Integration ProjectHow should the integration projects be structured? Integrations must be defined and scoped out in the early iterations of the project. An initial iteration should define the various data sources and how the data will be used in the project. In building this initial list, the following requirements questions can be used for each data source that must interact with the new system:1. Where does that data live? Possible answers: Excel,

The WhatWhat are integrations? Integrations are bringing data and business processes together from separate systems. Wikipedia describes System Integration as this[6]: “In information technology, systems integration is the process of linking together different computing systems and software applications physically or functionally, to act as a coordinated whole. The system integrator brings together discrete systems utilizing a variety of techniques such as computer networking, enterprise application integration, business process management or manual programming.” Integrations can range from… • The simple: Insertion of account data from a CSV file

into Salesforce every three months. • To the complex: A real-time, two-way integration

between Salesforce and a back-end system like SAP.

The WhyWhy are integrations important? First, integrations will form the building blocks of any successful project. Getting these integrations set-up correctly will determine how the rest of the system should and can function. Second, they are usually one of the most expensive parts of a project. While the data already probably lives in another system, the integrations usually take a while to map out. There will be multiple stakeholders involved in this mapping and any mapping process has an inherent complexity to it with different source and destination systems. It also takes time to get all the actual technical pieces in place to make them function properly.

Data involved in these integrations should be defined as having a System or Record (SOR). A SOR defines [2] “the authoritative data source for a given data element or piece of information.” The data must be moved in a process that will retain the integrity of that data in respect to the SOR. Along with the data itself, these existing

Integrations are the cornerstone of a project and the overall success of the project will depend on them. They must be properly understood and described so the project has a chance to succeed both in budget and in practice. This whitepaper will address the topic of integrations from the first discovery meetings to the final endpoint being connected and tested. Integrations will first be defined and then the importance of integrations will be detailed. The initial structure of the project and the iterations involved during the building of the integrations will then be described. Next an example of an integration between SQL Server and Salesforce using VB.NET will be worked through in detail. Finally, questions about testing will be covered. Salesforce will be used as the frame of reference for the technologies used for integrations in this document.

Page 3: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

3

Siebel, SAP, Oracle, Access, SQL Server, csv file or somebody’s head.

2. How often is this data source modified? The answer to this will help determine how the integration can be structured and how often it must be run.

3. How often should this data be refreshed in the new system? Possible answers: As soon as it changes in the source system, nightly, weekly, quarterly or yearly.

4. Is this data source the ‘System of Record’ (SOR)? The SOR is the system that is the authoritative data source for that data. This is very important to note as this is the system that will be used as the correct reference if there are any data conflicts.

5. Does this data source have to be in the first iteration or is it part of a future project? Many times getting one key integration up and running will help determine how long a project will take.

6. How can this data be moved between systems? In which directions should the data flow? With Salesforce we would talk about these options with the flow of data… a) The data is pushed into Salesforce. Some possible ways to do this are… i) The Apex Data Loader. This is a local executable that must be installed on a Windows machine.

- The Apex Data Loader can be run manually or through command line calls that can be kicked off by .bat files. It supports inserts, updates and a special combination of those called an upsert. ii) Data can be inserted by using the Partner or Enterprise API calls. iii) Data can be pushed to a custom web service written in Apex. - Usually a middle-ware product like PI or WebMethods would be used to push this request. iv) Once data is pushed into Salesforce Apex triggers can be used to transform the data as needed. b) The data is pulled into Salesforce. i) Apex in Salesforce can call external web services to pull data. c) The data in Salesforce needs to be pushed to another system. i) The Apex Data Loader can retrieve data from Salesforce.

ii) Apex in Salesforce can call external web services to push data. iii) A Batch job can be set up in APEX to push data on a defined schedule, like once a night.7. Who are the business users who know the data in

this data source and its rules? 8. Who are the technical users who will know how to

move the data in and out of that data source?9. Which specific data elements need to be moved?

During the discovery/estimation a ballpark number should be used… 10 or less, 10-100, 100-500, 500+

10. Write a short business description of each data source. This will help the business users understand where this data lives in their own terms and wording.

11. Write a short technical description of each data source. This will help the technical users understand where this data lives in their own terms and wording.

12. Are there privacy or security requirements for the data? Examples would be Social Security Numbers, Credit Card Numbers or Passwords.

13. Are there data quality concerns? (de-duplication, data enrichment)

14. Are there specific keys to identify data between systems?

These questions will build out an initial deliverable to the project for each data source that could look like this: 1. System Name i) SAP data2. Business Description i) Where all orders are processed. ii) Business Contacts(s): John Smith iii) Users log directly into the system iv) Reports are done in the system and in a local data mart3. Technical Description i) SAP system that is accessible through middle- ware interfaces ii) Technical Contacts: Jane Smith iii) There are two tables and around 50 fields to map to new system iv) Real-time integration is required4. Vendor Role or Implementation Team i) Design custom objects and relationship in new system

Page 4: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

4

ii) Implement the import of the data from the source system5. Client Role or Source System Team i) Define the fields that must exist in the new system and their relationships ii) Pull data from source system into a common data format6. Future Plans i) This integration will be maintained by Team A7. Priority/Timeline i) This data source must be implemented in Phase 1

Completing this initial discovery iteration early in the project will allow the other portions of the project to get started on the right foot. For example, if there is a web site or an application being built off of the data in the new system, it will be very important to get a view of how that data is going to be available in the new system after the integration.

In addition to this early documentation about the individual integration points a few big-picture diagrams can be put together to give the stakeholders a nice high-level visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the Unified Modeling Language (UML). Two of the diagrams described in the book are the class diagram and the activity diagram. The most common of these diagrams in integration projects is a class diagram. A class diagram describes the types of objects in the system and the various kinds of static relationships that exist among them[3]. This class diagram can be used to show how the data from the various integrations will fit together in the final system.

An activity diagram, which can show the work flow of the organization, showing how software and human activities interact[3]. The activity diagram can be useful in producing use-cases also.

Another diagram that is very important is an overall systems architecture diagram. This will show the systems that will be integrated and direction that the data will flow. The diagram included on the following page has aspects of both the class diagram and the systems architecture diagram.

The HowThese initial iterations and deliverables for the integrations should be part of an iterative process under an Agile Software Development process. The Manifesto of Agile Software Development at http://agileManifesto.org details the values and principles of the Agile Software processes. A scrum[4][5] approach within the agile software development family can be a guiding framework for the project. The decisions made when designing and implementing integrations will deeply affect the systems that will be built upon the new data. For this reason, iterations should be kept to a small timeline no greater than one week. Each iteration meeting should be an open meeting where key stakeholders can listen in and provide feedback early in the process. Using an Agile/Scrum approach with one-week sprints for this works very well. The team can: 1. Agree to what will be worked on for the next week on

Monday during a sprint planning meeting.2. Attend stand-up meetings on Tuesday, Wednesday

and Thursday so all stakeholders can listen in on how the current sprint is progressing.

3. Finish on Friday with a sprint review and retrospective.

This tight iteration schedule should provide high transparency to the process and give great visibility to these key integration decisions so they can be made properly as early in the project as possible. If user stories, story points and planning-poker sessions are implemented properly, the timeline of all these integrations in the project should come into clear view after the first couple of sprints. This is very important as the other pieces built on top of these integrations, like web-sites or applications, may depend on the completion of these integrations to get started.

How can these integrations be implemented?For this part of the paper, the focus will be on Salesforce. Salesforce is known for its great Customer Relationship Management (CRM) system and being a cloud-based Software as a Solution (SaaS) provider. Let’s look at an example of how a solution for a specific integration can be built. A common integration example is copying a number of fields from one system into

Page 5: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

5

Salesforce or vice-versa. A goal in this type of integration is not to hard-code the field names so future field additions or removals can be handled easily. One option is to make the mapping of these fields a table-driven process so it can be changed on the fly. Another option is to make the code interrogate the schema of the Salesforce structures using the ‘describe’ methods and then to parse the XML generically using the native XML parsing functions in APEX. If a match is found between the schema in Salesforce and the node in the xml, then the data will be copied. This, combined with the table-driven process mentioned earlier or a simple straight match by column names, can produce a system where it is very easy to add or remove fields in the future.

The Details within an ExampleLet’s take a deep dive into the implementation details of one integration example from end-to-end. Use Case: We need to have a nightly job that runs which will copy new account data from a SQL Server database into our Salesforce database. The solution will use a VB.NET console application that will pull data from SQL Server and push data to Salesforce using the Enterprise API. This VB.NET console exe will be kicked off by a nightly task at 1am by the Windows Scheduler tool. This integration is a very simple one using few fields so the effort to not hard-code the field names was not used. The agile and scrum processes tell us to solve the problems in the simplest way to start.

A starting point to all integrations is a diagram showing the relationships between the systems and the directional flow of data. OmniGraffle for Mac or Microsoft Visio on Windows are good applications for creating this type of diagram.

Notice that the diagram is showing the separation of the different locations for the data. The order of sequence is defined by the arrows flowing between the different locations and by the arrows within the integration layer itself.

Let’s build it! Here are the steps.1. Install Visual Studio for .NET2. Start Visual Studio3. Select ‘New Project’4. Select ‘Console Application’5. Name your project6. Rename your module from ‘main1’ to something

generic like ‘moveData’7. Go to the properties of the project and make sure the

namespace ‘System.Data’ is imported8. Import the Enterprise API from Salesforce

i) To get the WSDL for the Enterprise API log into Salesforce, then select Your Name, Setup, Develop, API, Generate Enterprise API. In Mozilla FireFox, right-click on the page and choose ‘Save Page As…’. Set the File Name to be ‘enterprise. wsdl’. ii) Now bring the WSDL into Visual Studio. Click on Project, Add Service Reference, Type your path into the Address box and hit Go. Rename the Namespace to be ‘Enterprise API.’ Click on OK.

9. In the app.Config file, I changed these values in the binding section: maxBufferSize=”1024000”; maxReceivedMessageSize=”1024000”; readerQuotas: maxArrayLength=”32768”; maxNameTableCharCount=”32768”

Page 6: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

6

Source CodeApp.config file – Service Model Section

<system.serviceModel> <bindings> <basicHttpBinding> <binding name=”SoapBinding” closeTimeout=”00:01:00”openTimeout=”00:01:00” receiveTimeout=”00:10:00” sendTimeout=”00:01:00” allowCookies=”false” bypassProxyOnLocal=”false” hostNameComparisonMode=”StrongWildcard”maxBufferSize=”1024000” maxBufferPoolSize=”524288” maxReceivedMessageSize=”1024000” messageEncoding=”Text” textEncoding=”utf-8” transferMode=”Buffered” useDefaultWebProxy=”true”><readerQuotas maxDepth=”32” maxStringContentLength=”8192”maxArrayLength=”32768” maxBytesPerRead=”4096” maxNameTableCharCount=”32768” /> <security mode=”Transport”> <transport clientCredentialType=”None” proxyCredentialType=”None”realm=”” /> <message clientCredentialType=”UserName” algorithmSuite=”Default” /> </security> </binding> </basicHttpBinding> </bindings> <client> <endpoint address=”https://login.salesforce.com/services/Soap/c/24.0” binding=”basicHttpBinding” bindingConfiguration=”SoapBinding” contract=”EnterpriseAPI.Soap” name=”Soap” /> </client></system.serviceModel>

Module VB.NET CodeImports System.Data.SqlClientModule moveData Private sessionID As String Private sessionURL As String Private Const field_systemKey As String = “systemKey” Private Const field_name As String = “name” Private Const field_number As String = “number”

Sub Main()

Dim dtAccounts As New DataTable Dim sfAccounts() As EnterpriseAPI.Account

Console.WriteLine(“Start of moving data from SQL Server to Salesforce with Enterprise API”) dtAccounts = retrieveSQLServerData()

Page 7: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

7

If IsNothing(dtAccounts) Then logAction(“No accounts to move today”) Return End If sfAccounts = fillSalesforceAccounts(dtAccounts) saveToSalesforce(sfAccounts) Console.WriteLine(“End of moving data from SQL Server to Salesforce with Enterprise API”) ‘This ReadLine will cause the console to wait for you to hit the enter key. Comment this out before deploying Console.ReadLine()

End Sub

Function retrieveSQLServerData() As DataTable Dim dtAccounts As New DataTable Dim con As New SqlConnection Dim cmd As New SqlCommand Dim adapter As New SqlDataAdapter

Try ‘con.ConnectionString = “Data Source=LOCALHOST;Initial Catalog=SalesforceData;User ID=sa;Password=***********” Console.WriteLine(“Opening connection to SQL Server”) con.ConnectionString = “Data Source=ServerName;Initial Catalog=SalesforceData;Integrated Security=True” con.Open() Console.WriteLine(“Connection Successful”) cmd.Connection = con cmd.CommandText = “SELECT [ID], [“ & field_name & “], [“ & field_number & “], [“ & field_systemKey & “] FROM [Account]”

adapter.SelectCommand = cmd Console.WriteLine(“Retrieving from SQL Server”) adapter.Fill(dtAccounts) Console.WriteLine(“Retrieving from SQL Server Successful”)

Catch ex As Exception logAction(“Error selecting from SQL Server. Details: “ & ex.ToString) Return Nothing Finally adapter.Dispose() cmd.Dispose() con.Close() End Try

Return dtAccounts

End Function

Private Function fillSalesforceAccounts(ByRef dtAccount As DataTable) As EnterpriseAPI.Account()

Page 8: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

8

Dim sfAccounts() As EnterpriseAPI.Account Dim sfAccount As EnterpriseAPI.Account

ReDim sfAccounts(dtAccount.Rows.Count - 1)

Console.WriteLine(“Creating Salesforce Account Objects for Upsert”) For i = 0 To dtAccount.Rows.Count - 1 sfAccount = New EnterpriseAPI.Account sfAccount.Name = dtAccount.Rows(i).Item(field_name) sfAccount.AccountNumber = dtAccount.Rows(i).Item(field_number) sfAccount.systemKey__c = dtAccount.Rows(i).Item(field_systemKey) sfAccounts(i) = sfAccount Next

Return sfAccounts

End Function

Sub saveToSalesforce(ByRef sfAccounts() As EnterpriseAPI.Account) Dim sfSoapSessionHeader As EnterpriseAPI.SessionHeader Dim myUpsertResult As EnterpriseAPI.UpsertResult Dim myDebuggingInfo As EnterpriseAPI.DebuggingInfo Dim myUpsertRequest As New EnterpriseAPI.upsertRequest Dim myUpsertRequestResponse As New EnterpriseAPI.upsertResponse Dim myPackageVersions(0) As EnterpriseAPI.PackageVersion Dim myPackageVersion As New EnterpriseAPI.PackageVersion Dim myAllOrNoneHeader As New EnterpriseAPI.AllOrNoneHeader Dim myDebuggingHeader As New EnterpriseAPI.DebuggingHeader Dim myEmailHeader As New EnterpriseAPI.EmailHeader Dim myStreamingEnabledHeader As New EnterpriseAPI.StreamingEnabledHeader Dim myMruHeader As New EnterpriseAPI.MruHeader Dim myAssignmentRuleHeader As New EnterpriseAPI.AssignmentRuleHeader Dim myAllowFieldTruncationHeader As New EnterpriseAPI.AllowFieldTruncationHeader Dim myDisableFeedTrackingHeader As New EnterpriseAPI.DisableFeedTrackingHeader Dim sfSoapClient2 As EnterpriseAPI.SoapClient Dim loopI As Integer Dim loopJ As Integer Dim loopK As Integer Dim insertCount As Integer = 0 Dim updateCount As Integer = 0 Dim errorCount As Integer = 0 Dim errorMessages As String = “” Dim insertMessage As String = “” Dim updateMessage As String = “”

Page 9: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

9

Console.WriteLine(“Building Upsert Request”) ‘This is only needed if queries are being done ‘Dim myQueryOptions As New EnterpriseAPI.QueryOptions ‘myQueryOptions.batchSize = 200 ‘myQueryOptions.batchSizeSpecified = True

myAllOrNoneHeader.allOrNone = True myDebuggingHeader.debugLevel = EnterpriseAPI.DebugLevel.Db myEmailHeader.triggerAutoResponseEmail = False myEmailHeader.triggerOtherEmail = False myEmailHeader.triggerUserEmail = False myStreamingEnabledHeader.streamingEnabled = True myMruHeader.updateMru = False myAssignmentRuleHeader.assignmentRuleId = “” myAssignmentRuleHeader.useDefaultRule = True myAllowFieldTruncationHeader.allowFieldTruncation = False myDisableFeedTrackingHeader.disableFeedTracking = True

myPackageVersions(0) = myPackageVersion

‘This upsert can be called this way or the way listed below with just the upsert request object ‘Dim myUpsertResults() As EnterpriseAPI.UpsertResult ‘myDebuggingInfo = sfSoapClient.upsert(sfSoapSessionHeader, myAssignmentRuleHeader, _ ‘ myMruHeader, myAllowFieldTruncationHeader, myDisableFeedTrackingHeader, _ ‘ myStreamingEnabledHeader, myAllOrNoneHeader, myDebuggingHeader, _ ‘ myPackageVersions, myEmailHeader, field_systemKey, sfAccounts, myUpsertResults)

‘First log into Salesforce to get the Session ID If LogInToSource() = False Then Return End If

sfSoapSessionHeader = New EnterpriseAPI.SessionHeader() sfSoapSessionHeader.sessionId = sessionID

myUpsertRequest.AllOrNoneHeader = myAllOrNoneHeader myUpsertRequest.AllowFieldTruncationHeader = myAllowFieldTruncationHeader myUpsertRequest.AssignmentRuleHeader = myAssignmentRuleHeader myUpsertRequest.DebuggingHeader = myDebuggingHeader myUpsertRequest.DisableFeedTrackingHeader = myDisableFeedTrackingHeader myUpsertRequest.EmailHeader = myEmailHeader myUpsertRequest.externalIDFieldName = field_systemKey & “__c” myUpsertRequest.MruHeader = myMruHeader myUpsertRequest.SessionHeader = sfSoapSessionHeader myUpsertRequest.sObjects = sfAccounts myUpsertRequest.StreamingEnabledHeader = myStreamingEnabledHeader myUpsertRequest.PackageVersionHeader = myPackageVersions

Page 10: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

10

‘SOAP is the name field in the endpoint node in the app.config file ‘<client> ‘ <endpoint address=”https://login.salesforce.com/services/Soap/c/24.0” ‘ binding=”basicHttpBinding” bindingConfiguration=”SoapBinding” ‘ contract=”EnterpriseAPI.Soap” name=”Soap” /> ‘</client> sfSoapClient2 = New EnterpriseAPI.SoapClient(“Soap”, sessionURL)

Console.WriteLine(“Sending Upsert Request”) Try myUpsertRequestResponse = sfSoapClient2.EnterpriseAPI_Soap_upsert(myUpsertRequest) Catch ex As Exception Console.WriteLine(“Error in Upsert. Details: “ & ex.ToString) logAction(“Error in Upsert. Details: “ & ex.ToString) Return End Try

myDebuggingInfo = myUpsertRequestResponse.DebuggingInfo

Console.WriteLine(“Loop through Upsert Request Results”) For loopI = myUpsertRequestResponse.result.GetLowerBound(0) To myUpsertRequestResponse.result.GetUpperBound(0) myUpsertResult = myUpsertRequestResponse.result(loopI) If myUpsertResult.created Then insertCount += 1 If insertMessage.Length > 0 Then insertMessage = insertMessage & “; “ End If insertMessage = insertMessage & insertCount.ToString & “: ID: “ & myUpsertResult.id End If If myUpsertResult.created = False And myUpsertResult.success Then updateCount += 1 If updateMessage.Length > 0 Then updateMessage = updateMessage & “; “ End If updateMessage = updateMessage & insertCount.ToString & “: ID: “ & myUpsertResult.id End If If myUpsertResult.success = False Then errorCount += 1 If errorMessages.Length > 0 Then errorMessages = errorMessages & “; “ End If If IsNothing(myUpsertResult.id) OrElse myUpsertResult.id = “” Then errorMessages = errorMessages & “ID: “ & myUpsertResult.id End If For loopJ = myUpsertResult.errors.GetLowerBound(0) To myUpsertResult.errors.GetUpperBound(0)

Page 11: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

11

errorMessages = errorMessages & “; “ & myUpsertResult.errors(loopJ).message For loopK = myUpsertResult.errors(loopJ).fields.GetLowerBound(0) To myUpsertResult.errors(loopJ).fields.GetUpperBound(0) errorMessages = errorMessages & “; “ & myUpsertResult.errors(loopJ).fields(loopK) Next Next End If Next

logAction(“Insert Message - Count: “ & insertCount & “ Details: “ & insertMessage & vbCrLf & vbCrLf & _ “Update Message - Count: “ & updateCount & “ Details: “ & updateMessage & vbCrLf & vbCrLf & _ “Error Message - Count: “ & errorCount & “ Details: “ & errorMessages) End Sub

Private Function LogInToSource() As Boolean

Dim sfLoginScopeHeader As New EnterpriseAPI.LoginScopeHeader Dim sfLoginResult As EnterpriseAPI.LoginResult Dim sfSoapClient As EnterpriseAPI.SoapClient sfSoapClient = New EnterpriseAPI.SoapClient

sfLoginScopeHeader.organizationId = “” sfLoginScopeHeader.portalId = “”

Console.WriteLine(“Loggin In”) sfLoginResult = sfSoapClient.login(sfLoginScopeHeader, “MyUserName”, “MyPassword”)

If sfLoginResult.passwordExpired Then Console.WriteLine(“Password Expired”) logAction(“Password Expired”) Return False End If

If sfLoginResult.sessionId.Length = 0 Then Console.WriteLine(“Login Failed”) logAction(“Login Failed”) Return False End If

sessionID = sfLoginResult.sessionId sessionURL = sfLoginResult.serverUrl Console.WriteLine(“Session ID: “ & sessionID) Console.WriteLine(“Session URL: “ & sessionURL)

Return True End Function

Page 12: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

12

Private Sub logAction(ByVal messageToSend As String) Console.WriteLine(messageToSend) ‘Maybe send an email ‘Maybe log to the Application Event Log End Sub

End Module

Notes About the CodeThe tricky part when getting started with the Salesforce API is understanding that a login call is required first to return the sessionID and the serverURL. Then those values can be used to make as many subsequent API calls as needed. This first login call is done in the LogInToSource method and the sfLoginResult object holds these two needed values: sessionID and serverURL. The sessionID is then used in the saveToSalesforce method on the sessionHeader object. The serverURL is used in the constructor of the SoapClient. Once these two items are in place, the SoapClient can be used to make whatever API calls are available.

Notice in the saveToSalesforce method that an array of Account objects are being passed. The great thing about the Enterprise API is that it gives you the object structures to work with since it is generated from a strongly typed WSDL. We could have also used the Partner API to do this work. But with the Partner API we would have needed to use generic objects since the Partner API is a loosely typed WSDL.

The logAction method at the end would be a great place to send an email to the individual maintaining the integration and put detailed notes in a log file or the Application Event Log.

Do Not Forget the TestingHow should these integrations be tested? First, understand that these integrations are the cornerstone and backbone of the system, so testing at the integration level is paramount. The integrations must be designed and then tested so that they fail as infrequently as possible. But it must be known that these integrations will fail. When they do fail, the integrations must fail gracefully so that the business can still function and data integrity is maintained.

When testing the integrations the developers and testers should make great use of automated tests. Data is being pushed back and forth between systems and automated tests can do a great job of testing each field one-by-one for accuracy. This field-by-field testing will be invaluable in the future when the system invariably starts to change as the business needs begin to adjust. Salesforce does have one area in integration test in this regard that you need to plan for in your unit tests. Salesforce cannot do external web service calls during a test. So a test cannot be set up to push data to an external data source like SAP, then do a query from SAP and then compare the data. The integration tests will need to be set up to test that data to be sent to another system is done consistently each time. One example is that the test could pretend that it is the destination system and could check the xml for required values. Another example is that the test can take a sample piece of XML from the external system and make sure that it is processed consistently. This will again be invaluable when the xml parameters between systems change over time and the changes to the integration will need to be re-tested.

ConclusionUnderstanding that integrations are integral to the success of a project is a first step to working with them. Make sure that quality diagrams are produced and good questions are asked to document the interacting systems in the project. The knowledge will help the implementers of the integrations to make better decisions during the tight iterations in the agile process. There are many ways to code the integrations, so pick a technology that fits the users who will code the initial project and those that will support it in the future. Finally, do not neglect the testing as these integrations will surely change over time.

Page 13: Integrations – From StartPoint to EndPoint...visual of the interacting parts. Martin Fowler’s book UML Distilled[3] describes many of the diagrams that can be produced with the

Integrations – From StartPoint to EndPoint | Terry Luschen

13

References

[1] - Enterprise application integration. Retrieved June 1, 2012 from http://en.wikipedia.org/wiki/Enterprise_application_ integration

[2] - System of record. Retrieved May 15, 2012 from http://en.wikipedia.org/wiki/System_of_record

[3] - UML DISTILLED – Third Edition, Martin Fowler, 2004 by Pearson Education, Inc.

[4] - Essential Scrum, Tobias Mayer, 2008, Baldwin-Wallace College Professional Development Retrieved June 6, 2012 from http://www.bw.edu/academics/cpd/forums/Cleveland_PMI_Scrum.pdf

[5] - Scrum (development). Retrieved June 8, 2012 from http://en.wikipedia.org/wiki/Scrum_(development)

[6] - System integration. Retrieved June 8, 2012 from http://en.wikipedia.org/wiki/System_integration

[7] – Manifesto for Agile Software Development. Retrieved May 23, 2012 from http://agileManifesto.org