1

I am trying to update a field in salesforce and for some reason it doesn't do anything. here is my code:

class Salesforce {

    private static $mySforceConnection;

    private static $instance;

    private function __construct() {
        self::$mySforceConnection = new \SforceEnterpriseClient();
        self::$mySforceConnection->createConnection(storage_path("app/wsdl/wsdl.xml"));
        self::$mySforceConnection->login();
    }
 
    static public function updateOppertunityStatus($status,$recordId){

        $records = new \stdClass();
        $records->ID = $recordId;
        $records->Status__c = $status;
        self::$mySforceConnection->update($records,'Opportunity');
    }

}

I can connect to salesforce and retrieve data and for some reason, the update does not give me an error but not updating the field. also checked that the ID is correct.

Thanks

5
  • After calling update what does the response look like from the Salesforce server? Is it an HTTP 200?
    – nbrown
    Mar 8, 2021 at 13:49
  • for some reason I am getting this error: "message: "Id not specified in an update call" what should I do? Mar 8, 2021 at 18:12
  • The error is actually really helpful in this case. It's letting you know at least one of the $records passed to update is missing an Id. I am not familiar with the PHP library you're using but I would double-check that $recordId is not null in updateOppertunityStatus and that $records->ID is valid syntax. Check that ID isn't causing issues on the SOAP API side and that the API isn't expecting lowercase id or Id.
    – nbrown
    Mar 8, 2021 at 18:28
  • I tried all the combined cases for id (ID,Id,id) none of them work. i pass correct values for the recordId also checked Mar 8, 2021 at 19:40
  • Hi, for some reason it said that the id is null but this is the object I pass: ``` Status__c: "Completed (Full)" fields: null id: "0065A00001bIdfPQAS" type: "Opportunity" ``` Mar 9, 2021 at 10:42

1 Answer 1

1

ok. I solved the issue. it seems that were two mistakes the id suppose to be written Id and the object suppose to be in an array:

  static public function updateOppertunityStatus($status,$recordId){

        $records = new \stdClass();
        $records->Id = $recordId;
        $records->Status__c = $status;
        $update = self::$mySforceConnection->update(array($records),'Opportunity');
        return $update;
    }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .