Friday, 4 September 2015

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=""/>

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.

  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','',null,'1','1','true'};
        private String[] passwordExpired_type_info = new String[]{'passwordExpired','',null,'1','1','false'};
        private String[] sandbox_type_info = new String[]{'sandbox','',null,'1','1','false'};
        private String[] serverUrl_type_info = new String[]{'serverUrl','',null,'1','1','true'};
        private String[] sessionId_type_info = new String[]{'sessionId','',null,'1','1','true'};
        private String[] userId_type_info = new String[]{'userId','',null,'1','1','true'};
        private String[] userInfo_type_info = new String[]{'userInfo','',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'','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.


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

Now the desired endpoint URL will look like

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=""> for sandbox
<soap:address location=""> for production/developer org

How to make pageblock section to be collapsed by default

Hi All,

We can achieve it through java script.

<apex:page standardController="Account">
<apex:pageBlock id="block1">
    <apex:pageBlockSection id="section1" columns="2" collapsible="true" title="Collapsebale Section">
        <apex:inputField value="{!Account.Name}"/>
         <apex:inputField value="{!Account.Phone}"/>
<script> twistSection(document.getElementById('{!$Component.block1.section1}').getElementsByTagName('img')[0]) </script>

Normal Section

Collapsed Section