Query a Salesforce org from any external tool such as SOAP UI or Postman, for example to look up a Contact by email.
Using the Enterprise SOAP API, log in to retrieve a sessionId, then send SOQL queries to the returned serverUrl.
Preparation
- Check that API is enabled in Setup > API
- Download the WSDL with βGenerate Enterprise WSDLβ > βGenerateβ
- Get you login URL in
<soap:address location="https://login.salesforce.com/services/Soap/c/XX/XX"/> - Get you security token from Profile > Settings > Reset My Security Token. It will be sent via Email.
Walkthrough
Login to retrieve sessionId
Create a request with the login URL, the headers Content-Type=text/xml, SOAPAction="" and the following request:
<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>[Your Salesforce Username]</urn:username>
<urn:password>[Concatenate Salesforce Password and Security Token]</urn:password>
</urn:login>
</soapenv:Body>
</soapenv:Envelope>Response:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<serverUrl>XXX</serverUrl>
<sessionId>XXX</sessionId>
<userId>XXX</userId>
<userInfo>[...]</userInfo>
</result>
</loginResponse>
</soapenv:Body>
</soapenv:Envelope>SOQL Query
- Create another request with the endpoint set as the previous
serverUrl - Use below request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:enterprise.soap.sforce.com" xmlns:urn1="urn:sobject.enterprise.soap.sforce.com">
<soapenv:Header>
<urn:SessionHeader>
<urn:sessionId>[sessionId]</urn:sessionId>
</urn:SessionHeader>
</soapenv:Header>
<soapenv:Body>
<urn:query>
<urn:queryString>
SELECT Id FROM Contact WHERE Email = '[email protected]'
</urn:queryString>
</urn:query>
</soapenv:Body>
</soapenv:Envelope>Response:
<?xml version="1.0" encoding="UTF-8"?>
<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" xmlns:sf="urn:sobject.enterprise.soap.sforce.com">
<soapenv:Header>
<LimitInfoHeader>
<limitInfo>
<current>2643</current>
<limit>XXXXX</limit>
<type>API REQUESTS</type>
</limitInfo>
</LimitInfoHeader>
</soapenv:Header>
<soapenv:Body>
<queryResponse>
<result>
<done>true</done>
<queryLocator xsi:nil="true"/>
<records xsi:type="sf:Contact">
<sf:Id>XXXXX</sf:Id>
</records>
<size>1</size>
</result>
</queryResponse>
</soapenv:Body>
</soapenv:Envelope>Going further
- Marketing Cloud REST API: the REST equivalent for Marketing Cloud
- Apex cheatsheet: SOQL, DML & Dates