Salesforce WebService Integration


Salesforce WebService Integration

Content

  • Description
  • Requirements
  • Writing WebMethod
  • Exposing WebMethod
  • Consuming WebMethod
  • Notes 

1. Description

Nowadays the business becomes more complex. To make B2B transactions successfully, the Salesforce Web Service plays a major role. Salesforce comes with various solutions to provide their consumers to expose organization data to external systems for data integrity. Salesforce provides both provider and consumer approach to the World. Using Webservice Salesforce enables you as a provider you can expose your org data to the World. 

2. Requirements

  • Salesforce Connected-App
  • Integration-User Setup
  • Salesforce Apex Class
  • External Tools to Test

3. Writing Web Method

Apex Class

4. Exposing Web Method

Before writing Web Method, you need to configure connected app. 

A connected app is a framework that enables an external application to integrate with Salesforce using APIs and standard protocols, such as SAML, OAuth, and OpenID Connect. Connected apps use these protocols to authenticate, authorize, and provide single sign-on (SSO) for external apps.

https://help.salesforce.com/articleView?id=sf.connected_app_overview.htm&type=5

Using Connected App, you will get Client ID and Client Secret.

Setup à Create à App à Connected App à New




 



After creating the connected app, you will get consumer key and consumer secret.

Create an Integration User of Integration API Only Profile and get Integration user id, password and Security token.

5. Consuming WebMethod

 Consuming a Webservice Method needs 2 steps

  • Authentication URL for generating security token
  • Using security token to send payload (XML Body) to Salesforce.
 Authenticate URL for generating security token.
 Method: Post
 URL: https://test.salesforce.com/services/oauth2/token?grant_type=password&client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&username=xxxxxxxxxxxxxxxxxxxxxxxxxx&password=password+securitytoken
   

        Use "access_token" (security token) received from token URL inside <cc:sessionId> tag of body   content to send payload (XML Body) to target Salesforce org.

        Use the below settings to submit the lastName as a parameter to CreateCustomer Webservice.


       Method: Post

       URL: https://test.my.salesforce.com/services/Soap/class/CreateCustomer

       Header:

  •     SOAPAction – CreateContact
  •     Content-Type -- text/xml

       Body:

     <?xml version="1.0" encoding="utf-8"?>   <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cc="http://soap.sf  orce.com/schemas/class/CreateCustomer">

      <soapenv:Header>

         <cc:SessionHeader>

            <cc:sessionId>

                xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

            </cc:sessionId>

         </cc:SessionHeader>

      </soapenv:Header>

      <soapenv:Body>

         <cc:CreateContact>

            <cc:lastName>MANAS</cc:lastName>

         </cc:CreateContact>

      </soapenv:Body>

    </soapenv:Envelope>

   
   

       6Note

  •      You can use the postman or SOAP API to consume web service for testing purpose
             https://www.postman.com/downloads/



Comments

Post a Comment

Popular posts from this blog

SFDX Simplified

Connect Salesforce REST API Using JavaScript