• Pierre Hausheer
  • NEWBIE
  • 10 Points
  • Member since 2016
  • Principal Consultant
  • Arctan Analytics Pte Ltd


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies

Recently I got stuck with storing leads to SF via CURL calls, it was working perfectly before and somehow it stopped a few weeks ago.

I must emphasize that I didn't do any code changes which could possibly cause this function to fail.

Here is a part of my code:

//Initialize the $kv array for later use
$kv = array();

foreach ($prepare_data as $key => $value) {
    $kv[] = stripslashes($key)."=".stripslashes($value);
}

//Create a query string with join function separted by &
$query_string = join("&", $kv);

//Check to see if cURL is installed ...
if (function_exists('curl_init')) {

    $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8';

    //Open cURL 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($kv));
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);

    //Set some settings that make it all work :)
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, FALSE);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);

    //Execute SalesForce web to lead PHP cURL
    $result = curl_exec($ch);

    //close cURL connection
    curl_close($ch);

}

$prepare_data variable has key/value pairing of SF fields. Keys are set from the HTML generated form.

I would appreciate help from someone who else have/had similar issues to try to solve this.

Thanks in advance

Hi - when doing the challenge "Bulk Apex Trigger" in Trailhead I get the error message :"Executing against the trigger does not work as expected."

I have checked the name of the class, task name as mentioned in the challenge description.

I have copied the code below :

trigger ClosedOpportunityTrigger on Opportunity (before insert, before update) {
  List<Task> taskList = new List<Task>();

    //If an opportunity is inserted or updated with a stage of 'Closed Won'
    // add a task created with the subject 'Follow Up Test Task'.
    for (Opportunity opp : [SELECT Id,Name FROM Opportunity
                     WHERE Id IN :Trigger.new AND StageName = 'Closed Won']) {
       //add a task with subject 'Follow Up Test Task'.
       taskList.add(new Task(Subject='Follow Up Test Task', WhatId = opp.id ));                
  }
                          
    if (taskList.size() > 0) {
        insert taskList;
    }



Thank you
Pierre-Alain