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

How to make pageblock section to be collapsed by default

Hi All,

We can achieve it through java script.

<apex:page standardController="Account">
<apex:form>
<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}"/>
    </apex:pageBlockSection>
    
<script> twistSection(document.getElementById('{!$Component.block1.section1}').getElementsByTagName('img')[0]) </script>
</apex:pageBlock>
</apex:form>
</apex:page>

Normal Section


Collapsed Section