+ Reply to Thread
Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14
This is a discussion on How do I select one record and display the result within the Salesforce Coding Discussions forums, part of the Salesforce category; Eliana, this is what you would do! You would have your form
  1. #11
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16

    Okay this should help

    Eliana,

    this is what you would do!

    You would have your form like you want process


    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title>Add information To Leads</title>
    </head>
    <body>
      <center><img src="http://www.salesforce.com/us/assets/developer/adn_logo.gif" alt="" border="0"></center>
      <form action="process.php" method="post">
          <table width="40%" align="left">
            <tr>
              <td>Would you like more information: </td>
              <td>Yes<input type="radio" name="yes" value="yes" /></td>
              <td>No<input type="radio" name="no" value="no" /></td>
              <input type="hidden" name="leadid" value="<?php echo $_GET['leadid']; ?>" />
            </tr>
            <tr>
              <td colspan="2"><input type="submit" name="submit" value="submit"></td>
            </tr>
          </table>
        </form>
      </body>
    </html>
    you would then send the ID in a hidden field, you can see that in a form. The action of the form, in this case, is a script called process.php


    PHP Code:
    <?php

    ini_set
    ("soap.wsdl_cache_enabled""0");
    error_reporting(E_ERROR E_WARNING E_PARSE E_NOTICE);

    require_once (
    './includes/soapclient/SforcePartnerClient.php');
    require_once (
    './includes/soapclient/SforceHeaderOptions.php');

    if (isset(
    $_POST['submit']))
    {


        
    $_POST['id'] = $_POST['leadid'];
        unset(
    $_POST['leadid']);
        
    $username 'you@youremail.com';
        
    $password 'password';
        
    $key 'iwx7bDGIU0OCOOwnaKa0llSfY';

        
    //setup update to Salesforce


        //Go get the accounts by $account_name
        
    try
        {
                
    //salesforce  wsdl
              
    $wsdl './includes/soapclient/partner.wsdl.xml';

              
    //connect to salesforce
              
    $client = new SforcePartnerClient();
              
    $client->createConnection($wsdl);
              
    $loginResult $client->login($username$password.$key);

              
    $sObject = new sObject();
              
    $sObject->type 'Leads';
              
    $sObject->fields $_POST;

              
    $result $client->update(array($sObject));

              if (
    $result->success)
              {
                  echo 
    'thank you for choosing our products, someone will contact you shortly';
              }
              else
              {
                  
    $error '<pre>' print_r($resulttrue) . '</pre>';
                  
    mail('you@youremail.com''Lead update error''Something happend on the upate'$error);
              }


        }
        catch (
    exception $e)
        {
            
    // This is reached if there is a major problem in the data or with
            // the salesforce.com connection. Normal data errors are caught by
            // salesforce.com
            
    echo '<pre>' print_r($etrue) . '</pre>';
            return 
    false;
            exit;
        }

    }


    ?>
    You have clearly define your $_POST names and vales for the fields you want to update so they will match your salesforce field names:

    example:

    if you had a custom field in your leads object in salesforce called ContactMe__c, then the name in your field would be "ContactMe__c", such as:

    Code:
    <td>Yes<input type="radio" name="ContactMe__c" value="true" /></td>
    <td>No<input type="radio" name="ContactMe__c" value=false" /></td>
    <input type="hidden" name="leadid" value="<?php echo $_GET['leadid']; ?>" />
    the <?php echo $_GET['leadid']; ?> is the ID like in your example > www.mywebsite.com/survey.php?leadid=xxxxxxxxx , this would be the ID of the of the lead record that you want to update in Salesforce, such as a06R0000003tXzgIAE


    I hope this helps and let me know if this is what you are looking for!!

    ~Mike

  2. #12
    eliana is offline Junior Member
    Join Date
    May 2009
    Posts
    7
    Thank you so much, this looks easy, however I am getting an error:
    Fatal error: Class 'sObject' not found in C:\wamp\www\salesforce2\update.php

    <?php
    ini_set("soap.wsdl_cache_enabled", "0");
    error_reporting(1);
    require_once ('soapclient/SforceEnterpriseClient.php');
    require_once ('soapclient/SforceHeaderOptions.php');
    require_once ('soapclient/SforceBaseClient.php');
    if (isset($_POST['submit_btn']))
    {

    $_POST['id'] = $_GET['id'];
    //setup update to Salesforce

    //Go get the accounts by $account_name
    try
    {
    $mySforceConnection = new SforceEnterpriseClient();
    $mySoapClient = $mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
    $mylogin = $mySforceConnection->login("login", "password + token");
    $sObject = new sObject();
    $sObject->type = 'Leads';
    $sObject->fields = $_POST;
    $result = $client->update(array($sObject));
    if ($result->success)
    {
    echo 'thank you for choosing our products, someone will contact you shortly';
    }
    else
    {
    $error = '<pre>' . print_r($result, true) . '</pre>';
    mail('you@youremail.com', 'Lead update error', 'Something happend on the upate'. $error);
    }

    }
    catch (exception $e)
    {
    // This is reached if there is a major problem in the data or with
    // the salesforce.com connection. Normal data errors are caught by
    // salesforce.com
    echo '<pre>' . print_r($e, true) . '</pre>';
    return false;
    exit;
    }
    }
    ?>

  3. #13
    eliana is offline Junior Member
    Join Date
    May 2009
    Posts
    7
    I got it!!!!!! (this is still a test, I have to work on the form like you said with the hidden fileds, etc)

    require_once ('soapclient/SforceEnterpriseClient.php');
    require_once ('soapclient/SforceHeaderOptions.php');
    try {
    $mySforceConnection = new SforceEnterpriseClient();
    $mySoapClient = $mySforceConnection->createConnection("soapclient/enterprise.wsdl.xml");
    $mylogin = $mySforceConnection->login("login", "password");
    $userResult = $mylogin->userInfo;
    // echo $userResult->userFullName . ', your session id is ' . $mylogin->sessionId;
    $sObject = new stdClass;
    $sObject->FirstName = 'Eliana1';
    $sObject->Id = '123';

    $response = $mySforceConnection->update(array ($sObject), "Lead");
    // print_r($response);
    } catch (Exception $e) {
    echo $e->faultstring;
    }
    ?>

  4. #14
    mike's Avatar
    mike is offline Administrator
    Join Date
    May 2007
    Location
    Wylie, Texas
    Posts
    607
    Blog Entries
    16
    That is great ma'am, I am glad that you got it working!

    Do one thing though, make sure that you do not include your salesforce username and password in the hidden fields so they can be viewed in the source of the HTML. I am sure you wont, but I just wanted to remind you


    Let me know if there is anything else you need help with

    ~Mike

+ Reply to Thread
Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.2