Header sample.gif

Contents

API Methods

This chart provides sample Force.com SOAP API calls with the PHP Toolkit.

Method Description Enterprise Partner
convertLead Converts a Lead into an Account, Contact, or (optionally) an Opportunity. sample sample
create, delete, and undelete Adds, deletes, and undeletes one or more new individual objects to your organization's data. sample sample
describeGlobal Retrieves a list of available objects for your organization's data. sample sample
describeLayout Retrieves metadata about page layouts for the specified object type. sample sample
describeSObject Retrieves metadata (field list and object properties) for the specified object type. sample sample
emptyRecycleBin Delete records from the recycle bin immediately. sample sample
fieldsToNull Nullifies fields sample sample
getDeleted Retrieves the IDs of individual objects of the specified object that have been deleted since the specified time. sample sample
getServerTimestamp Retrieves the current system timestamp (GMT) from the Force.com Web service. sample sample
getUpdated Retrieves the IDs of individual objects of the specified object that have been updated since the specified time. sample sample
getUserInfo Retrieves personal information for the user associated with the current session. sample sample
login Logs in to the login server and starts a client session. sample sample
merge Merge up to three records into one. sample sample
query Executes a query against the specified object and returns data that matches the specified criteria. sample sample
queryMore Retrieves the next batch of objects from a query. sample sample
processSubmitRequest Process Submit Request (Workflow) sample sample
processWorkItemRequest Process Work Item Request (Workflow) sample sample
resetPassword Changes a user's password to a server-generated value. sample sample
retrieve Retrieves one or more objects based on the specified object IDs. sample sample
search Executes a text search in your organization's data. sample sample
sendEmail Compose and send email. sample sample
setPassword Sets the specified user's password to the specified value. sample sample
update Updates one or more existing objects in your organization's data. sample sample
upsert Upserts one or more existing objects in your organization's data. sample sample


Metadata API Calls

Method Description
create Create a custom object via the Metadata API sample
delete Delete a custom object via the Metadata API sample
checkStatus Check the status of a Metadata create or delete operation via the Metadata API sample


Header Options

Method Description Enterprise Partner
AssignmentRuleHeader Specifies the assignment rule to use when creating or updating an Account, Case, or Lead. sample sample
CallOptions This header options replaces the setClientId method in the old toolkits. sample
EmailHeader Specify whether or not to send an email when these events sample sample
QueryOptions Specifies the batch size for queries. Batches that are larger or smaller than the specified size may be used, in order to maximize performance. sample sample


Other Samples

Query (with related objects) Sample Code

<?php
require_once ('../soapclient/SforcePartnerClient.php');
require_once ('../soapclient/SforceHeaderOptions.php');

try {
  	$mySforceConnection = new SforcePartnerClient();
  	$mySoapClient = $mySforceConnection->createConnection('../soapclient/partner.wsdl.xml');
  	$mylogin = $mySforceConnection->login("username@yourdomaincom", "changeme");

	$query = "SELECT c.Id, c.FirstName, c.LastName, a.Name
			 from Contact c, c.Account a WHERE c.Id ='".$sfid."'"; 

	$result = self::$mySforceConnection->query($query);
	$sObject = new SObject($result->records[0]);
	var_dump($sObject);

	echo "<br />First:".$sObject->fields->FirstName;
	echo "<br />Last:".$sObject->fields->LastName;
	echo "<br />Company:".$sObject->sobjects[0]->fields->Name;

	print_r($result);

} catch (Exception $e) {
  	echo $mySforceConnection->getLastRequest();
  	print_r($e);
}
?>

Creation of Master and Detail records with Error Checking

The goal of this code is to take input from a form and create a master record (a case) and multiple detail records. The HTML form and the PHP are below. My favorite part is that the detail lines are repeated over and over and you don't need to specify different form variables for each line.

<HTML>
<HEAD>
<TITLE> Test Master Detail
</TITLE>
</HEAD> 
<BODY>
<form method="post" action="doit.php">
Name: <Input name="Name" type="text">
Sold To: <input name="Sold_to" type="text">
Ship To: <input name="Ship_to" type="text">
email: <input name="Email" type="text">
<HR>
part no: <input name="partno[]" type="text">
Qty: <input name="qty[]" type="text">
Desc: <input name="desc[]" type="text">
<BR>
part no: <input name="partno[]" type="text">
Qty: <input name="qty[]" type="text">
Desc: <input name="desc[]" type="text">
<BR>
part no: <input name="partno[]" type="text">
Qty: <input name="qty[]" type="text">
Desc: <input name="desc[]" type="text">
<BR>
part no: <input name="partno[]" type="text">
Qty: <input name="qty[]" type="text">
Desc: <input name="desc[]" type="text">
<BR>
<input type="submit">
</form>
</BODY>
</HTML>

This is the PHP Code that the form calls:

<HTML>
<HEAD>
<TITLE> Test for Master Detail
</TITLE>
</HEAD> 
<BODY>

<?php

/*  
   	Case and line items
*/

//  SFDC Required 

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

// prepare connection to salesforce.com

   $loginResult = null;
   try {
    $mySforceConnection = new SforcePartnerClient();
    $mySforceConnection->createConnection("partner.wsdl.xml");
    $loginResult = $mySforceConnection->login("api@yourorg.com", "password");
   } catch (Exception $e) {
    echo "error connecting to salesforce.com!";
    echo $e->faultstring;
   }

// Create new case from Form Variables

    $name = $_POST['Name'];
    $sold = $_POST['Sold_to'];
    $ship = $_POST['Ship_to'];
    $email = $_POST['Email'];
    $fieldsToUpdate
      = array('Delphi_Rep_Name__c'=>$name,'SuppliedEmail'=>$email,'Ship_To_Account_Number__c'=>$ship,'Sold_to_Account_Number__c'=>$sold);
    $sObject = new SObject();
    $sObject->fields = $fieldsToUpdate;
    $sObject->type = 'Case';
	try {
    $CreateResponse = $mySforceConnection->create(array ($sObject));
    } catch (Exception $e) {
    echo "<BR>Error Creating the Case! ";
    echo $e->faultstring;
	exit;
    }

// Make sure the case was created successfully.

    if($CreateResponse->success != 1) {
		echo "<BR>Error Creating the case. ";
	    print_r($CreateResponse->errors->message);
		exit;
	}

// Get the Case ID of the succefully created case.

$CaseId = $CreateResponse->id;

// Loop through line items

   $Lines = array();

foreach ($_POST['partno'] as $row=>$partno)
{
   $qty = $_POST['qty'][$row];
   $desc = $_POST['desc'][$row];
   $fieldsToUpdate2
      = array('Part_Number__c'=>$partno, 'qty__c'=>$qty, 'Part_Description__c'=>$desc,'Case__c'=>$CaseId);

    $sObject2 = new SObject();
    $sObject2->fields = $fieldsToUpdate2;
    $sObject2->type = 'Part_Line_Item__c';
    if ($partno != '') {
    array_push($Lines, $sObject2);
	}
}

// Send create for line items.

   try {
    $LineItems = $mySforceConnection->create($Lines);
   } catch (Exception $e) {
    echo "<BR>Error Adding line Items to the case!";
    echo $e->faultstring;
	exit;
   }

// Make sure all the line items were added.
// If checks for case of only one line item created
// foreach checks for case when multiple line items created

 if($LineItems->success != 1) {

	foreach ($LineItems as $LIs)
	{
		if($LIs->success != 1) {
		echo "<br>Error Adding the line items. ";
	    print_r($LIs->errors->message);
		exit;
	    }
	}
 }


 ?>
<h1>Thank You</h1>
<br>
Your case has been submitted.  You will receive an email notification.
</BODY>
</HTML>