I am creating a web lead by doing a curl like so

   //set POST variables
    $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';
    $fields = array(
            'Event_City__c' => urlencode($ch_register_event_city), // custom fields
            'Register_DOB__c' => urlencode($ch_register_dob),
            'Register_Emergency_Contact__c' => urlencode($ch_register_emergency_name),
            'Register_Emergency_Phone__c' => urlencode($ch_register_emergency_phone),
            'Register_Release__c' => urlencode($ch_register_agree),
            'No_Text__c' => urlencode($ch_register_no_text),
            'Under_18__c' => urlencode($ch_register_under_age),
            'Volunteer_Option__c' => urlencode($ch_register_volunteer_option),
            'Register_Release_Name__c' => urlencode($ch_register_signiture),
            'Register_Release_Date__c' => urlencode($ch_register_signiture_date),
            'lead_source' => 'Outreach Volunteer',
            'oid' => $ch_register_salesforce_id, // insert with your id 
            'retURL' => urlencode('thank-you/'), // sending this just in case
            'debug' => '0',
            'debugEmail' => urlencode(""), // your debugging email

    //url-ify the data for the POST
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }

    //open connection
    $ch = curl_init();

    //set the url, number of POST vars, POST data

    curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE);

    //execute post
        $result = curl_exec($ch);

    //close connection

Is there any way to get the ID of the lead created in a response??? I need the ID after this lead is created for another part of the code (send that lead an Adobe echoSign agreement). And unfortunately the only way to connect the two in SF is this way, I can't just send the form to the email or else they live separately in SF.

Thanks! Any option would be great. I dont have to use the web-lead way if there is a better way from their API. Just need the ID in a response. I just feel like its possible since when I have debug on I get an email with the ID in the email

  • If you're using Web2Lead, until the lead is inserted into the database, you won't have an ID. There's no "roundtrip" that I'm aware of between the form that submits the lead and the Salesforce Instance after the lead is loaded for insertion. My understanding is that Salesforce simply "delivers" the form to the Salesforce instance for processing. If it returned anything, I'd expect it to need to be through messaging services via workflow after insertion. – crmprogdev May 13 '16 at 16:40

Web to Lead is an asynchronous process. When you send a lead to that address, it won't be processed until sometime later. This allows salesforce.com to collect leads even when a database is down for maintenance, instead of disrupting customers' ability to capture leads.

If you want the ID back, you have to use another process. These have already been described both on this forum and elsewhere, so I won't go in to great detail. Just do a search for "web 2 lead api" or something like that. Three easy possibilities are to use the SOAP API, REST API, or create a public anonymous Sites API (keep in mind, you'll have to build your own security for that solution).

You'll also have to engineer a way to preserve leads that are generated until services are available in the event of a maintenance window or authentication issue.

  • Ya, my next thought process was on the thank you page after the lead is created, get the lead id by email then run the echo sign process. Whats the best way in php in get the lead via email? or can you? – Packy May 13 '16 at 17:10
  • @Packy If you're using web2lead, there's no guarantee that the lead will be created by the time the thank you page is displayed (in fact, it probably won't be created yet). If you use an API, you can get the ID back immediately. Once the lead makes it into salesforce, there's so many things you could do, including an outbound message, sending an email, running Apex Code, or so on. Since email is also asynchronous in nature, you'd have to have your script pick up the new emails periodically. Not impossible, to be sure, but possibly complicated depending on the server. – sfdcfox May 13 '16 at 17:19
  • Got ya. Makes sense. So you are saying ditch the web to lead and login using a session and create the lead that way? I am already using a session to login to send the adobe form – Packy May 13 '16 at 17:22
  • 1
    @Packy Yes, a session is the easiest way to get your data back in real time. You'll also have a much higher limit than you would if you were using web2lead (500 per day, if I recall correctly). – sfdcfox May 13 '16 at 17:27
  • Wow! That work and my respose was the Lead ID with EAE on the end for some reason. But I have fields I added to the lead such as "event city", can I add them to the curl? – Packy May 13 '16 at 17:50

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.