2

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(
            'last_name'=>urlencode($ch_register_last_name),
            'first_name'=>urlencode($ch_register_first_name),
            'street'=>urlencode($ch_register_street),
            'city'=>urlencode($ch_register_city),
            'state'=>urlencode($ch_register_state),
            'zip'=>urlencode($ch_register_zip),
            'description'=>urlencode($ch_register_event_city),
            'email'=>urlencode($ch_register_email),
            'phone'=>urlencode($ch_register_phone),
            '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.'&'; }
    rtrim($fields_string,'&');


    //open connection
    $ch = curl_init();

    //set the url, number of POST vars, POST data
    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST,count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

    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
        curl_close($ch);

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

1
  • 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
    Commented May 13, 2016 at 16:40

1 Answer 1

0

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.

6
  • 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
    Commented May 13, 2016 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
    Commented May 13, 2016 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
    Commented May 13, 2016 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
    Commented May 13, 2016 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
    Commented May 13, 2016 at 17:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .