I'm trying to integrate Salesforce with another service using the REST API, but it doesn't have a way to convert leads. I found this other answer:

How do you convert a Lead via the REST API?

but I don't have the option to make an Apex class. Is there a way I could convert a lead in REST without using an Apex class?


The Partner API SOAP method convertLead() is at its core an HTTP POST request where the Body is XML that conforms to to the WSDL.

There is nothing stopping you from building up that XML string and posting it to the required URL (including the required SessionId). If you need you can even parse the XML response.

I don't want to get into the differences between SOAP and REST (follow the link for that). However, if you can call the Salesforce REST API using an HTTP POST you can coerce a call to the SOAP message.

Sample SOAP body for the HTTP POST request:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:partner.soap.sforce.com">
            <urn:convertedStatus>Closed - Converted</urn:convertedStatus>

This should be POSTed to https://instance.salesforce.com/services/Soap/u/33.0. You will need to replace instance with your pod identifier. It will be something like na5. look for it in the URL sub domain when you login to Salesforce. It will be the same domain that you send the REST API requests to.

The sessionId will, in most cases, be interchangeable with the access_token used in the Authorization: Bearer header with the REST API.

So you should already have most of the details you require.

  1. Create the URL to POST to based on the REST API URL domain. Send it to /services/Soap/u/33.0 to get the SOAP Partner API.
  2. Take the access_token you already have to use as the sessionId.
  3. Build up a string to be the SOAP XML body. Put your sessionId between the <urn:sessionId> XML tags. Put your leadId between the <urn:leadId> tags.
  4. POST the string to the URL your created in Step 1.
  • Do you think you could explain it for someone who's never used SOAP before, and uses JSON with REST? I'm not sure where I should be sending this, what data I'd need to put in the POST, or where to get the sessionID? Would I be able to pass this as JSON or does it have to be XML? – mfournier Apr 1 '15 at 17:18
  • @mfournier I've updated the answer. It should just be a bit of string manipulation. A tool like Postman for Chrome would make this easy to experiment with. – Daniel Ballinger Apr 1 '15 at 22:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.