Webtolead SOAP Apex 服务错误 PHP

Webtolead SOAP Apex service Error PHP

我想将数据提交到 SFDC 中的潜在客户表单,这是我的代码:

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

// Salesforce.com credentials
$sfdcUsername = "SFDC_USERNAME";
$sfdcPassword = "SFDC_PASSWORD";
$sfdcToken = "SFDC_TOKEN";
// the email address to search for. could also use a post/get variable
//$searchEmail = 'phpblogtest@noemail.com';

$sfdc = new SforcePartnerClient();
// create a connection using the partner wsdl
$SoapClient = $sfdc->createConnection("soapclient/PartnerWSDL.xml");
$loginResult = false;

try {  
    // log in with username, password and security token if required
    $loginResult = $sfdc->login($sfdcUsername, $sfdcPassword.$sfdcToken);
} catch (Exception $e) {
    global $errors;
    $errors = $e->faultstring;
    echo "Fatal Login Error <b>" . $errors . "</b>";
    die;
}

$parsedURL = parse_url($sfdc->getLocation());
define ("_SFDC_SERVER_", substr($parsedURL['host'],0,strpos($parsedURL['host'], '.')));  
define ("_WS_NAME_", "WebToLeadServices2");  
define ("_WS_WSDL_", "soapclient/" . _WS_NAME_ . ".xml");  
define ("_WS_ENDPOINT_", 'https://' . _SFDC_SERVER_ . '.salesforce.com/services/wsdl/class/' . _WS_NAME_);  
define ("_WS_NAMESPACE_", 'http://soap.sforce.com/schemas/class/' . _WS_NAME_);

$client = new SoapClient(_WS_WSDL_);
$sforce_header = new SoapHeader(_WS_NAMESPACE_, "SessionHeader", array("sessionId" => $sfdc->getSessionId()));
$client->__setSoapHeaders(array($sforce_header));

try {

    $sObject = new stdclass();
    $sObject->fullName = 'Smith';
    $sObject->mobileNumber = '1234567896';
    $sObject->emailAddress = 'rakesh@netbiz.in';
    $sObject->source = 'DIGITAL MARKETING';


    // call the web service via post
    $wsParams=array('fullName'=>'rakesh shetty','mobileNumber'=>'1234567896','emailAddress'=>'rakesh@example.in','source'=>'DIGITAL MARKETING');
    $response = $client->createLeadFromWeb($sObject);
    // dump the response to the browser
    print_r($response);

// this is really bad.
} catch (Exception $e) {
    global $errors;
    $errors = $e->faultstring;
    echo "Ooop! Error: <b>" . $errors . "</b>";
    die;
}

WebToLeadServices2.xml :

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Web Services API : WebToLeadServices
-->
<definitions targetNamespace="http://soap.sforce.com/schemas/class/WebToLeadServices" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://soap.sforce.com/schemas/class/WebToLeadServices">
 <types>
  <xsd:schema elementFormDefault="qualified" targetNamespace="http://soap.sforce.com/schemas/class/WebToLeadServices">
   <xsd:element name="AllowFieldTruncationHeader">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="allowFieldTruncation" type="xsd:boolean"/>
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>
   <xsd:element name="CallOptions">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="client" type="xsd:string"/>
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>
   <xsd:element name="DebuggingHeader">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="categories" minOccurs="0" maxOccurs="unbounded" type="tns:LogInfo"/>
      <xsd:element name="debugLevel" type="tns:LogType"/>
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>
   <xsd:complexType name="LogInfo">
    <xsd:sequence>
     <xsd:element name="category" type="tns:LogCategory"/>
     <xsd:element name="level" type="tns:LogCategoryLevel"/>
    </xsd:sequence>
   </xsd:complexType>
   <xsd:simpleType name="LogCategory"> //-------->Line no 37
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="Db"/>
     <xsd:enumeration value="Workflow"/>
     <xsd:enumeration value="Validation"/>
     <xsd:enumeration value="Callout"/>
     <xsd:enumeration value="Apex_code"/>
     <xsd:enumeration value="Apex_profiling"/>
     <xsd:enumeration value="Visualforce"/>
     <xsd:enumeration value="System"/>
     <xsd:enumeration value="All"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="LogCategoryLevel">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="None"/>
     <xsd:enumeration value="Internal"/>
     <xsd:enumeration value="Finest"/>
     <xsd:enumeration value="Finer"/>
     <xsd:enumeration value="Fine"/>
     <xsd:enumeration value="Debug"/>
     <xsd:enumeration value="Info"/>
     <xsd:enumeration value="Warn"/>
     <xsd:enumeration value="Error"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:simpleType name="LogType">
    <xsd:restriction base="xsd:string">
     <xsd:enumeration value="None"/>
     <xsd:enumeration value="Debugonly"/>
     <xsd:enumeration value="Db"/>
     <xsd:enumeration value="Profiling"/>
     <xsd:enumeration value="Callout"/>
     <xsd:enumeration value="Detail"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:element name="DebuggingInfo">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="debugLog" type="xsd:string"/>
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>
   <xsd:element name="SessionHeader">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="sessionId" type="xsd:string"/>
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>
   <xsd:simpleType name="ID">
    <xsd:restriction base="xsd:string">
     <xsd:length value="18"/>
     <xsd:pattern value="[a-zA-Z0-9]{18}"/>
    </xsd:restriction>
   </xsd:simpleType>
   <xsd:complexType name="WebLead">
    <xsd:sequence>
     <xsd:element name="budget" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="capturePoint" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="country" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="dialingCode" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="emailAddress" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="fullName" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="IPAddress" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="mobileNumber" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="projectInterested" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="source" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="webbannerSize" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="webbannerSource" minOccurs="0" type="xsd:string" nillable="true"/>
    </xsd:sequence>
   </xsd:complexType>
   <xsd:complexType name="result">
    <xsd:sequence>
     <xsd:element name="message" minOccurs="0" type="xsd:string" nillable="true"/>
     <xsd:element name="recordId" minOccurs="0" type="tns:ID" nillable="true"/>
     <xsd:element name="returnCode" minOccurs="0" type="xsd:int" nillable="true"/>
    </xsd:sequence>
   </xsd:complexType>
   <xsd:complexType name="address">
    <xsd:complexContent>
     <xsd:extension base="tns:location">
      <xsd:sequence>
       <xsd:element name="city" type="xsd:string"/>
       <xsd:element name="country" type="xsd:string"/>
       <xsd:element name="countryCode" type="xsd:string"/>
       <xsd:element name="geocodeAccuracy" type="xsd:string"/>
       <xsd:element name="postalCode" type="xsd:string"/>
       <xsd:element name="state" type="xsd:string"/>
       <xsd:element name="stateCode" type="xsd:string"/>
       <xsd:element name="street" type="xsd:string"/>
      </xsd:sequence>
     </xsd:extension>
    </xsd:complexContent>
   </xsd:complexType>
   <xsd:complexType name="location">
    <xsd:sequence>
     <xsd:element name="latitude" type="xsd:double"/>
     <xsd:element name="longitude" type="xsd:double"/>
    </xsd:sequence>
   </xsd:complexType>
   <xsd:element name="createLeadFromWeb">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="wl" type="tns:WebLead" nillable="true"/>
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>
   <xsd:element name="createLeadFromWebResponse">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="result" type="tns:result" nillable="true"/>
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>
  </xsd:schema>
 </types>
 <!-- Message for the header parts -->
 <message name="Header">
  <part name="AllowFieldTruncationHeader" element="tns:AllowFieldTruncationHeader"/>
  <part name="CallOptions" element="tns:CallOptions"/>
  <part name="DebuggingHeader" element="tns:DebuggingHeader"/>
  <part name="DebuggingInfo" element="tns:DebuggingInfo"/>
  <part name="SessionHeader" element="tns:SessionHeader"/>
 </message>
 <!-- Operation Messages -->
 <message name="createLeadFromWebRequest">
  <part element="tns:createLeadFromWeb" name="parameters"/>
 </message>
 <message name="createLeadFromWebResponse">
  <part element="tns:createLeadFromWebResponse" name="parameters"/>
 </message>
 <portType name="WebToLeadServicesPortType">
  <operation name="createLeadFromWeb">
   <input message="tns:createLeadFromWebRequest"/>
   <output message="tns:createLeadFromWebResponse"/>
  </operation>
 </portType>
 <binding name="WebToLeadServicesBinding" type="tns:WebToLeadServicesPortType">
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="createLeadFromWeb">
   <soap:operation soapAction=""/>
   <input>
    <soap:header use="literal" part="SessionHeader" message="tns:Header"/>
    <soap:header use="literal" part="CallOptions" message="tns:Header"/>
    <soap:header use="literal" part="DebuggingHeader" message="tns:Header"/>
    <soap:header use="literal" part="AllowFieldTruncationHeader" message="tns:Header"/>
    <soap:body use="literal" parts="parameters"/>
   </input>
   <output>
    <soap:header use="literal" part="DebuggingInfo" message="tns:Header"/>
    <soap:body use="literal"/>
   </output>
  </operation>
 </binding>
 <service name="WebToLeadServicesService">
  <documentation></documentation>
  <port binding="tns:WebToLeadServicesBinding" name="WebToLeadServices">
   <soap:address location="https://cs2.salesforce.com/services/Soap/class/WebToLeadServices"/>
  </port>
 </service>
</definitions>

错误:System.NullPointerException:尝试取消引用空对象Class.WebToLeadServices.createLeadFromWeb:第 37 行,第 1 列

发生了什么问题。请帮助我提前致谢。

它对我有用。将这样的变量与您的必填字段一起传递。

$lead = new StdClass();
$lead->fullName = 'rakesh shetty';
$lead->mobileNumber = "1234567896";
$lead->emailAddress = "rakesh@example.in";
$lead->source = "DIGITAL MARKETING";
$leadData = array('wl'=>$lead);
$response = $client->createLeadfromWeb($leadData);