12 April 2015

Sample Salesforce SFDC Enterprise upsert

This is a sample SOAP Upsert using Enterprise WSDL. Note that we only passing the session Id  on the header information since we don't need the others and that the envelop must be posted to the ServerURL you got from the login call as per described in this blogpost. In addition, we need to put a value on the <externalIDFieldName> node with the field API name of the objects external Id. In this example, I used the Salesforce standard Id field.


<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"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header>
      <urn:SessionHeader>
         <urn:sessionId>Session ID from login call</urn:sessionId>
      </urn:SessionHeader>
   </soapenv:Header>
   <soapenv:Body>
      <urn:upsert>
         <urn:externalIDFieldName>Id</urn:externalIDFieldName>
         <urn:sObjects xsi:type="Account">
            <Id>0017000001ExVRDAA3</Id>
            <Name>Sample Account (Enterprise) Upserted</Name>
         </urn:sObjects>
      </urn:upsert>
   </soapenv:Body>
</soapenv:Envelope>

Below is the sample SOAP response:

<soapenv:Envelope 
     xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
     xmlns="urn:enterprise.soap.sforce.com">
   <soapenv:Header>
      <LimitInfoHeader>
         <limitInfo>
            <current>11</current>
            <limit>15000</limit>
            <type>API REQUESTS</type>
         </limitInfo>
      </LimitInfoHeader>
   </soapenv:Header>
   <soapenv:Body>
      <upsertResponse>
         <result>
            <created>false</created>
            <id>0017000001ExVRDAA3</id>
            <success>true</success>
         </result>
      </upsertResponse>
   </soapenv:Body>
</soapenv:Envelope>

NOTE:

The <createResponse> node will have the result of the call. The <id> will contain the record Id in SFDC for the record you are creating and the <success> will tell whether the call is successful or not.

*I noticed that SoapUI 5.0.0 does not automatically add the xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance". This is important when you are setting the object type <urn:sObjects> tag.

1 comment:

  1. i need urgent help on updating with different objects in single request..suppose i've custom objects A and B but they are not related to each other but i need to update the records. can u please provide me one sample xml. B object record should update with external id

    ReplyDelete