Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Former Member

1.     Introduction  and Business Requirement:

1.1.     We have seen lot of blogs/docs regarding SFDC and PI integration in SCN then what is new in this blog? Well, in this blog I would like to share my learning/experience on the integration of PI with SFDC in different approach which is very simple, easy and fast way to configure (initial set-up may take little time) and run the interface without any complexity. Without spending more time on what is SFDC cloud server and its CRM capabilities I will jump directly to business requirement/scenario that I am explaining in this blog as most of us know about SFDC.

          Client was having requirement to create eligible customers from SFDC to SAP ECC, Update back SAP customer number from SAP ECC to SFDC as response, Creation of Sales Orders from SFDC to SAP and Update SAP Sales Order Number/Date as response. There were lot of blogs/use case docs regarding SAP PI with SFDC integration in SCN. I followed the steps and  started implementing it in PI, but I felt little complexity in building this interfaces as we have to maintain Session IDs, two SOAP receivers, URL settings, Content type change etc. Then I had searched in SFDC Developers Force link, on how other applications are integrating with SFDC. I got some important info that using Java API generated from enterprise WSDL document provided by SFDC it would be very easy to integrate the SFDC with java applications.

          As SAP PI supports java mapping in Operation mapping, I started developing the code and leveraged it to login to SFDC server and do the DML operations by directly calling simple Java method calls without bothering on session IDs, SOAP message header, Server URLs, Content Type etc. At end, we successfully implemented these scenarios and they are running in production smoothly. So I thought to share this new way of integrating the SAP PI 7.31 with SFDC Cloud Server by leveraging the java mapping program to SAP Ecosystem Community so that others can also get benefit from this blog.

1.2.     Business Scenario:

          1.2.1. Retrieve all the new customer information from SFDC server having StageName field as 'Order Pending' and create the Customers in SAP ECC with retried data info and Update back the SAP customer number back to SFDC.

          1.2.2. Retrieve all the new Sales Order Information from SFDC and create Sales Orders in SAP with retried data and update the SAP Sales Order Number back to SFDC.

2.     Currently available solutions in PI:

2.1.     Third party REST adapters which ready to use to integrate with SFDC server.

2.2.     Third party solution/packages.

2.3.     Using PI SOAP Receiver adapters and adding session IDs in SOAP message header. Please check blog links given in reference section. These are little complex scenario and difficult to manage the sessions IDs.

3.     What is the benefit of this new approach (Leveraging PI Java Mapping):

3.1.     No need to have any PI SOAP Receiver adapters! in Integration Directory.

3.2.     No need to add session ID token in the SOAP message header as we are not going to use any SOAP messages at all! We will be to using SFDC java API calls that are generated from enterprise WSDL document.

3.3.     No need to have SOAP lookup code for retrieve the Session ID and No need to use Dynamic Configuration code to set the Sever URL, No need to use MessageTransformBean for changing the content type.

3.4.     Supports request and response messages using simple asynchronous interfaces (i.e. asynch-synch-asynch flow).

3.5.     Simple step to generate the APIs from SFDC enterprise WSDL document. Simple API call Connector.newConnection() to login to SFDC server, Simple API calls like EnterpriseConnection.Create(), update(), query() etc. for DML operations to process the data in SFDC server. Please see the java code below for further info.

3.6.     Simple steps to import Java mapping class, SFDC jars (enterprise.jar, wsc-22.jar) in ESR, simple steps to test the SFDC connection, easy  to troubleshoot as we can add custom log info using getTrace().addInfo() and re-throw the SFDC API exceptions back to PI Mapping runtime.

4.     About SFDC login and WSDL document:

4.1.     SFDC Server API login and Security Token: We use user id and password to login to SFDC server through web browsers, while connecting SFDC from applications e.g. PI, web services, applications need to login through API i.e. through SFDC API call, SOAP based/Rest based web service calls. While login to server through API, we need additional security password called Security Token along with your password. It will be alphanumeric long string that will unique to the particular user id which has to be passed along with password by appending it to password i.e. Mypassword+SecurityToken (without + char).

          You can generate/re-set this security token from SFDC server. Click on Personal Setup --> select My Personal Information --> Reset My Security Token. The new security token is sent to the email address of user.

If you are using any SOAP applications e.g. SOAP UI, PI SOAP adapter, you also need session Id to be passed in the SOAP Message header. You need to pass this every time while you hit the SFDC server and in some times, you have to maintain/manage this session IDs for complex transactions.  In our approach, we are login through SFDC APIs generated from enterprise WSDL, which does not require session ID to be maintained or to be added in the SOAP header! See 5.2.3 section for more info.

4.2.    SFDC Enterprise WSDL: To access the SFDC server’s Web services, you need a Web Service Description Language (WSDL) file.  SFDC provides the enterprise WSDL file to download from its server. Using this we can generate the APIs to login to SFDC server and do the DML Operations (Select/Insert/Update/Delete). We can download this WSDL by log in to your organization and click Setup --> Develop --> API, right-click on ‘Generate Enterprise WSDL’ and save it in local drive, rename the file from .xml to .wsdl.

4.3. Generating Enterprise.jar using WSDL: First download the SFDC’s wsc-22.jar file from at And to generate the enterprise.jar file, run the following command in command prompt. Provide the directory path of wsc-22.jar, enterprise.wsdl where these are stored and output directory path, make sure you have installed Java JDK 1.6+ in your system to run this command.

java –classpath pathToJAR/wsc-22.jar pathToWsdl/WsdlFilename  pathToOutputJar/OutputJarFilename

e.g. java –classpath C:\SFDC\wsc-22.jar C:\SFDC\enterprise.wsdl  C:\SFDC\enterprise.jar

5.     PI ESR Configurations:

5.1.     Below is Flow diagram of Retrieving SOs from SFDC updating in SAP data flow.

SAP side there will be a batch program running which will be scheduled in background, which will initiate the PI interface with asynch ABAP Proxy call. At receiver determination step, operation mapping is called and which in turn calls java program which does all the login to SFDC, issuing DML operations and processing of records returned from SFDC. Once DML operation is successful, java program forms the target message type structure and sends to receiver system. Since data is required at SAP ECC side, using receiver SOAP adapter in XI mode, asynch ABAP Proxy is called and forwards the records that is received from SFDC. Please refer below sections for java code.

5.2.     Java mapping code to login and to process SFDC data to do DML Operations:

5.2.1.     In SAP NWDS, create the class eg. PISelectSalesOrders which will extends the AbstractTransformation class so that it can override the transform() method. You need to import the enterprise.jar and wsc-22.jar file as library jars to compile the java code.

5.2.2.     Then next step is that in the transform() method, prepare a SQL Query string to be issued to SFDC Server, see below screen shot:

5.2.3.     Login to SFDC Server through API: Please check the below screen shot to connect to SFDC server by using Connector.newConnection()  method call, please note that, for password input you have send both SFDC login password appended with security token corresponding to the user id.

5.2.4.     Issue SQL query using connection.query(queryString) method by passing SQL query that you formed in previous steps and store the response from SFDC server in QueryResult object. Use getTrace.addInfo() after every operations so that you will get to know what step it crossed and it would be helpful in case of trouble-shooting.

5.2.5.     Process the Result using QueryResult object and form Target Message Type structure by using String builder object.

5.2.6.     Similar to above other DML Operations like create/Update and Delete can be used, in below screen shot you can see that code is updating back the SAP Sales Orders from SAP ECC to SFDC by using connection.update().

5.2.7.  Please note that from SFDC side, Opportunity.Id column is unique Id using which we can retrieve/update/delete the records in SFDC, so we need to store this value in SAP custom Z table (e.g. SFDC_Opportunity_ID field) when we first retrieve the data. Set the flags in Z table whenever we update back the SO number or customer number so that we should not update same records again and again.

5.3.     Importing SFDC jar files into ESR using Imported Archives: Once you are done with java mapping program and testing, import the generated enterprise.jar and wsc-22.jar files into ESR namespace using Imported Archives Object along with java mapping jar/zip file.

5.4.     Create the Operation Mapping in the ESR and assign java mapping program to it. Now we all set to do testing the connection and issuing DML queries to SFDC. Ready from ESR side.

5.5.     Before testing the java mapping make sure that you have disabled VM parameter|iaik.protocol as this will disable to use iaik security package as default security package. For connecting SFDC server using https protocol we need to use underlying Java security package.

6.     PI ID Configurations:

Since login and issuing DML commands are all happening in Operation Mapping (Java Program) there are only little configurations required at ID side.

6.1.     If we are having Update/Create Query (SAPàPIàSFDC) then we can use simple File adapter at Receiver side to complete end to end scenario and while interface determination, Operation Mapping would be called and does the Update/Create operation.

6.2.     If we are having Select Query (Batch ProgramàPIà SFDC for fetching data, SAPßPIßSFDC Updating to SAP) wherein we have to fetch all the records from SFDC depending condition and Update the retried data to SAP then we should have ABAP Batch Programà PIà ABAP Proxy scenario where operation mapping will fetch all the records and forma the target Message Type and it would be send across to ABAP Proxy. For PI point of view this transaction is asynchronous but in java mapping it is handling request-response messages.

6.3.     In case of any errors while login or DML operations, Java program would throw error with appropriate log and Operation mapping will get fail and interface would fail which will send out PI alert mail to respective support team.

7.     Summary:

In summary, using PI java mapping and SFDC enterprise WSDL document, wsc-22.jar and SFDC java APIs we can easily integrate the SFDC Cloud Server without worrying on Session IDs, SOAP Header, Server URLs and concentrate only on business logics and DML query.  I really enjoyed while writing java code after long timeJ, here with this I would like to conclude this blog. Comments are welcome.

8.     References:






Labels in this area