View Single Post
  #4  
Old 08-08-2007, 09:41 AM
mike mike is offline
Administrator
 
Join Date: May 2007
Posts: 273
Send a message via AIM to mike Send a message via MSN to mike Send a message via Yahoo to mike Send a message via Skype™ to mike

Sarma

Try this code, it worked for me: You will need your saleforce login, password and the account name:


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']))
{
    
$user trim($_POST['user']);
    
$pass trim($_POST['pass']);
    
$account_name htmlspecialchars(trim($_POST['a_name']));





    
//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($user$pass);

          
$accounts get_accounts($client$account_name);

          if (
$accounts)
          {
            echo 
"<table>\n";

              echo 
"<tr>\n";
              foreach (
$accounts as $r)
              {
                    
$r = new SObject($r);
                    echo 
"<td>Account Id&nbsp;<strong>".$r->Id"</strong></td>&nbsp;&nbsp;
                          <td>Account Name&nbsp;<strong>" 
.$r->fields->Name."</strong></td>\n";
              }
              echo 
"</tr>\n";
            echo 
"</table>\n";
          }
          else
          {
            echo 
"No Account Found By That Name";
          }
          exit;



    }
    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;
    }

}

/* functions */

function get_accounts($connection$name)
{
  
$query "SELECT Id, Name FROM Account WHERE Name =  '$name'";

  
$queryOptions = new QueryOptions(500);
  
$response $connection->query(($query), $queryOptions);
  
$accounts $response->records;

  return 
$accounts;
}
?>

<!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>Get Account From Salesforce.com</title>
</head>
<body>
  <center><img src="http://www.salesforce.com/us/assets/developer/adn_logo.gif" alt="" border="0"></center>
  <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
      <table width="100%" align="center">
        <tr>
          <td align="right">* Salesforce Username: </td>
          <td align="left"><input name="user" type="text" maxlength="50" align="right"></td>
        </tr>
        <tr>
          <td align="right">* Salesforce Password </td>
          <td align="left"><input name="pass" type="password" maxlength="50"></td>
        </tr>
        <tr>
          <td align="right">* Account Name To Search: </td>
          <td align="left"><input name="a_name" type="text" maxlength="50" align="right"></td>
        </tr>
        <tr>
          <td align="center" colspan="2"><input type="submit" name="submit" value="Check Account"></td>
        </tr>
      </table>
    </form>
  </body>
</html>
Reply With Quote