function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Developer99Developer99 

Ooop! Error: System.NullPointerException: Attempt to de-reference a null object Class.Ctest.cInsert

HI,

    we are connecting from php to salesforce,while connecting we are getting an error is
 
  Ooop! Error: System.NullPointerException: Attempt to de-reference a null object Class.Ctest.cInsert: line  a1.Name = req.accName;

 My Webservice class
 
global class Ctest
{
// Request Class
global class RequestClass
{
  webservice String accName;
}
// Response Class
global class ResponseClass
{
webservice String acName;
}

RequestClass req = new RequestClass();
webservice static ResponseClass  cInsert(RequestClass req)
{
 ResponseClass res = new ResponseClass();
   Account a1 = new Account();
   a1.Name = req.accName; // Error showing point
    insert a1;
  // Return Response
   res.acName = a1.Name;
   return res;
}
}

And my php code is

  require_once('salesforceAPI/soapclient/SforceEnterpriseClient.php');
require_once('salesforceAPI/soapclient/SforceHeaderOptions.php');

$sfdc = new SforceEnterpriseClient();
$SoapClient = $sfdc->createConnection('enterprise.wsdl.xml');

$loginResult = false;

$loginResult = $sfdc->login(USER, PASSWORD . SECURITY_KEY);

$parsedURL = parse_url($sfdc->getLocation());
define("_SFDC_SERVER_", substr($parsedURL['host'], 0, strpos($parsedURL['host'], '.')));
define("_WS_NAME_", 'salesforceAPI/Ctest');
define("_WS_WSDL_", _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));

$method = $client->__getFunctions();

$wsParams = array('accName' => 'XXXXXXX');

$client->cInsert($wsParams)
Vinita_SFDCVinita_SFDC
Hello,

With debug statements can you check what value are you getting for req.accName? 
Developer99Developer99

@Vinita_SFDC


   Can you suggest me how to check with debug statements in developer console for above webservice