Accessing SalesForce data using SOAP Service - SoapUi

Recently i was trying to figure out how to access SalesForce data from outside. I had two options either to use REST or use SOAP API for accessing the data. I tried both and these are my notes for accessing SalesForce Soap API using Soap client such as SoapUi.
  1. First thing that you would want to do is generate security token for salesforce. Follow these steps for generating security token
  2. Once you have security token, login into the SalesForce console to download the WSDL, Click on Develop -< API and you will see page where you can download all the WSDL's, Download the Enterprise WSDL
  3. Now create new SOAP Ui project using the Enterprise WSDL you just downloaded
    You will notice that it generates bunch of SOAP operations
  4. In order to use the SOAP API you will have to first send a login request to SalesForce and get sessionid once you have it you can use that for making subsequent calls. First call the Login service like this
    
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:urn="urn:enterprise.soap.sforce.com">
       <soapenv:Header>
       </soapenv:Header>
       <soapenv:Body>
          <urn:login>
             <urn:username>replacerwitheuserid</urn:username>
             <urn:password>replacewithpasswordreplacewithsecuritytoken</urn:password>
          </urn:login>
       </soapenv:Body>
    </soapenv:Envelope>
    
    You should replace replacerwitheuserid with your userId (email id that you use for login) and also replace replacewithpassword with your password and use the security token that you got in email to replace replacewithsecuritytoken. Make a request and you will get a response which looks like this
    
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns="urn:enterprise.soap.sforce.com" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Body>
          <loginResponse>
             <result>
                <metadataServerUrl>https://na15.salesforce.com/services/Soap/m/29.0/00Di0000000iKns</metadataServerUrl>
                <passwordExpired>false</passwordExpired>
                <sandbox>false</sandbox>
                <serverUrl>https://na15.salesforce.com/services/Soap/c/29.0/00Di0000000iKns</serverUrl>
                <sessionId>sessionId</sessionId> 
                <userId>userId</userId>
                <userInfo>
                   <accessibilityMode>false</accessibilityMode>
                   <currencySymbol>$</currencySymbol>
                   <orgAttachmentFileSizeLimit>5242880</orgAttachmentFileSizeLimit>
                   <orgDefaultCurrencyIsoCode>USD</orgDefaultCurrencyIsoCode>
                   <orgDisallowHtmlAttachments>false</orgDisallowHtmlAttachments>
                   <orgHasPersonAccounts>false</orgHasPersonAccounts>
                   <organizationId>xxxx</organizationId>
                   <organizationMultiCurrency>false</organizationMultiCurrency>
                   <organizationName>Self</organizationName>
                   <profileId>xxxx</profileId>
                   <roleId xsi:nil="true"/>
                   <sessionSecondsValid>7200</sessionSecondsValid>
                   <userDefaultCurrencyIsoCode xsi:nil="true"/>
                   <userEmail>xxxxx</userEmail>
                   <userFullName>Sunil Patil</userFullName>
                   <userId>xxxxx</userId>
                   <userLanguage>en_US</userLanguage>
                   <userLocale>en_US</userLocale>
                   <userName>sxxxxxx</userName>
                   <userTimeZone>America/Los_Angeles</userTimeZone>
                   <userType>Standard</userType>
                   <userUiSkin>Theme3</userUiSkin>
                </userInfo>
             </result>
          </loginResponse>
       </soapenv:Body>
    </soapenv:Envelope>
    
    You will need the value of sessionId element and value of serverUrl in subsequent requests. so note it down
  5. Next assume that you want to execute query request that will give you list of all the contacts using SELECT Id, FirstName, LastName From Contact query, so use XML that looks like this for the soap request. Replace the replacewithyoursessionid with the sessionId that you got from the login request and also change the URL where SOAP request is made to value of serverUrl
    
    <soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:urn="urn:enterprise.soap.sforce.com">
    
       <soapenv:Header>
          <urn:SessionHeader>
    <urn:sessionId>replacewithyoursessionid</urn:sessionId>
          </urn:SessionHeader>
       </soapenv:Header>
       <soapenv:Body>
          <urn:query>
             <urn:queryString>
    SELECT Id, FirstName, LastName  From Contact<
    /urn:queryString>
          </urn:query>
       </soapenv:Body>
    </soapenv:Envelo
    
    You will get response with list of contacts

2 comments:

Andria BZ said...

Well post in recent day’s customer relationship play vital role to get good platform in business industry, Salesforce crm tool helps you to maintain your customer relationship enhancement.
Regards,
Salesforce training in Chennai|Salesforce training institute in Chennai

sss said...

In many organizations today, resources are limited. A team might have the internal expertise to train others on a new system,but they might have several other priority projects to handle.For more details salesforce online training in hyderabad