Skip to main content

How will external system get SFDC service endpoint URL dynamically

Hi All,

This post is all about to avoid an integration issue(Service not available or invalid session id) when instance url get changed in SFDC. From SFDC side no need to perform any action ,but we can suggest appropriate approach of fetching endpoint url to external system so that communication will be smoother.

For an inbound integration SFDC has to provide two WSDL to external system.

  1. Partner WSDL (Required to generate session id )
  2. Service WSDL
In the service wsdl the endpoint URL will be <soap:address location="https://cs15.salesforce.com/services/Soap/class/YourWebserviceClassName"/>

So the external system will add endpoint URL in a property file or in some in configuration stuff, that is how webservice works.As we all know instance (cs15) used to change from environment to environment (QA to UAT), and instance will  also change when SFDC plan for refreshment of server. At that time we have to update external team about the new url otherwise they wont be able to connect the SFDC service. In order to avoid such issues,external system should follow below approach to get endpoint URL dynamically.

Solution
  1. Create stub classes for both WSDL(Partner and service).
  2. Invoke stub class's (generated from partner wsdl) below method.
public partnerSoapSforceCom.LoginResult login(String username,String password) {
            partnerSoapSforceCom.login_element request_x = new partnerSoapSforceCom.login_element();
            request_x.username = username;
            request_x.password = password;
            partnerSoapSforceCom.loginResponse_element response_x;
            Map<String, partnerSoapSforceCom.loginResponse_element> response_map_x = new Map<String, partnerSoapSforceCom.loginResponse_element>();
}

3. Login method will return below result.
public class LoginResult {
        public String metadataServerUrl;
        public Boolean passwordExpired;
        public Boolean sandbox;
        public String serverUrl;
        public String sessionId;

        public String userId;
        public partnerSoapSforceCom.GetUserInfoResult userInfo;
        private String[] metadataServerUrl_type_info = new String[]{'metadataServerUrl','urn:partner.soap.sforce.com',null,'1','1','true'};
        private String[] passwordExpired_type_info = new String[]{'passwordExpired','urn:partner.soap.sforce.com',null,'1','1','false'};
        private String[] sandbox_type_info = new String[]{'sandbox','urn:partner.soap.sforce.com',null,'1','1','false'};
        private String[] serverUrl_type_info = new String[]{'serverUrl','urn:partner.soap.sforce.com',null,'1','1','true'};
        private String[] sessionId_type_info = new String[]{'sessionId','urn:partner.soap.sforce.com',null,'1','1','true'};
        private String[] userId_type_info = new String[]{'userId','urn:partner.soap.sforce.com',null,'1','1','true'};
        private String[] userInfo_type_info = new String[]{'userInfo','urn:partner.soap.sforce.com',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:partner.soap.sforce.com','true','false'};
        private String[] field_order_type_info = new String[]{'metadataServerUrl','passwordExpired','sandbox','serverUrl','sessionId','userId','userInfo'};
    }

4. Take both sessionId and ServerUrl from login result class.
<serverUrl>https://cs15.salesforce.com/services/Soap/u/34.0/00De0000005VVRj</serverUrl>

<sessionId>00De0000005VVRj!AQ4AQCaFYonDr06YPr.lRtb7gHlmAMW8R9pFKRUvwJAyTUZrtET9puPvtRDe8By7_cI9j9QLVvaKukkn2E90fEAt.PlqULKA</sessionId>

5.From the response get value of service URL value and keep only yellow colored part (https://cs15.salesforce.com/services/Soap/) then append (class/YourWebserviceClassName) because class name is not going to be changed.

Now the desired endpoint URL will look like
https://cs15.salesforce.com/services/Soap/class/YourWebserviceClassName.

Note- With this approach external system will always get endpoint url dynamically , if instance url get changed they will get it in the response itself,  No need to update new endpoint url in the property file.

6. Now the final step they will setsessionId and new endpoint url before calling our service wsdl method.

For partner wsdl

Before providing partner wsdl to external system, SFDC team has to change address location as  below.
<soap:address location="https://test.salesforce.com"> for sandbox
<soap:address location="https://login.salesforce.com"> for production/developer org

Comments

Popular posts from this blog

How to Create a Tooltip in Lightning Datatable ?

Imagine you have a datatable displaying a list of Contact records , and one of the columns shows the Account Name . The Account Name is a hyperlink that allows users to navigate to the Account record page. But what if users want to take a quick glance at some key Account fields —like Phone or Address—without navigating to the Account record? In Salesforce Classic, this was achieved using the Mini Page Layout feature from standard page. However, in Lightning Experience, we can implement a similar feature by adding a tooltip to the data table. Solution Overview: We’ll create a Lightning Web Component (LWC) that: Displays a data table with a clickable Account Name . Provides a tooltip that shows the Account's Phone and Address fields when users hover over the Account Name. Implementation Steps: 1. Data Preparation We need to retrieve the following fields for each Contact and its associated Account: Contact Fields : Name, Phone, Email Account Fields : Name, Phone, Billing Addre...

Lifecycle hooks in LWC

There are 3 phase of LWC component  1. Mounting  A. constructor, B. connnectedCallback C. render D. renderedCallback 2. UnMounting  A. disconnectedcallback 3. Error  A.errorcallback Note - render is not lifecycle hook, it is protected method of Lightning element class. Mounting Phase LWC Creation and Render Life cycle Constructor Method ·        This method called when component is instantiated and It flows from parent to child component. ·        Need to call Super() inside constructor method ·        Can’t access any component properties or child component because it’s not ready yet. ·        Host element can be accessed through “this. template” inside constructor method. ·        Don’t add any attributes to host inside constructor C   constructor (){          super (); //...

Style in LWC

 Following are the ways we can apply in CSS in LWC. 1. Inline CCS Inline CSS is not recommended approaches, it is take highest priority among all CSS. style="color:green;font-size:10px;" is inline CSS added to div < template >     < lightning-card title = "Inline CSS" >         < div >             < div style = "color:green;font-size:10px;" > This is inline Style div </ div >         </ div >     </ lightning-card > </ template >  2. External CSS style can be applied to an elements such as h1, p,div span etc. It can applied to class using "." notation. for example .user{} It can also be applied to pseudo class.  for example .user:hover{} Id locator is not being used in LWC to apply style To apply external css, need to create separate CSS file, file name should be exactly matched with component name. for example - If component name is ...