Salesforce Lead update not working using PHP Toolkit

650 Views Asked by At

When I am trying to update the existing lead fields, but it is showing the below error. Please help where I am wrong.

CODES :

$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
$mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

$queryEmail = "SELECT Id, LastName, FirstName, Salutation, Title, Company, Street, City, State, PostalCode, Country, Phone, Email, Website, xxxxx__c FROM Lead WHERE Email='[email protected]'";
$resultEmail = $mySforceConnection->query($queryEmail);

$leadid=$resultEmail->records[0]->Id;

if($leadid!="") { 
$fields = array (
'LastName' => 'Update',  
'Company' => 'xxxxx xx',
'Title' => 'xyz xyz',
'xxxxx__c' => $resultEmail->records[0]->fields->xxxxx__c.(htmlspecialchars(strip_tags("update Message"), ENT_QUOTES, 'UTF-8'))  );
    $sObject = new SObject();
    $sObject->fields = $fields;
    $sObject->type = 'Lead';
    $sObject->Id =$leadid;
$createResponse = $mySforceConnection->update(array($sObject));

I am getting the following error.

ERROR:

stdClass Object
(
[errors] => stdClass Object
    (
        [fields] => 
        [message] => cannot reference converted lead
        [statusCode] => CANNOT_UPDATE_CONVERTED_LEAD
    )

[id] => 
[success] => 
)
1

There are 1 best solutions below

0
On

Finally, I am able to fix the issue with the help of salesforce professional.

Actually I created Lead which was converting to contact. I was facing the issue because I was updating with the lead ID while it should be updated with the contact ID. As lead converts to contacts.