3

I am having an issue with the Partner WSDL. When attempting to create a new opportunity over the API I am getting a return stating that required fields are missing. These fields are correctly being set prior to the message being sent. IN addition I have looked at the user logs and there are no errors with Validation rules etc... Below are samples of the object sent and the return.

Thanks for any help in advance!

Part of the object sent

object(SObject)#5 (2) {
  ["type"]=>
  string(11) "Opportunity"
  ["fields"]=>
  object(stdClass)#3 (48) {
    ["RecordTypeId"]=>
    string(18) "xxxxx"
    ["OwnerId"]=>
    string(18) "xxxxx"
    ["AccountId"]=>
    string(18) "xxxxx"
    ["CloseDate"]=>
    string(25) "2014-03-18T00:00:00-04:00"
    ["StageName"]=>
    string(25) "Closed"
    ["Name"]=>
    string(16) "test - delete me"
    }
}

Return message from API

   object(stdClass)#17 (3) {
    ["errors"]=>
    array(1) {
      [0]=>
      object(stdClass)#18 (3) {
        ["fields"]=>
        array(3) {
          [0]=>
          string(4) "Name"
          [1]=>
          string(9) "StageName"
          [2]=>
          string(9) "CloseDate"
        }
        ["message"]=>
        string(57) "Required fields are missing: [Name, StageName, CloseDate]"
        ["statusCode"]=>
        string(22) "REQUIRED_FIELD_MISSING"
      }
    }
    ["id"]=>
    NULL
    ["success"]=>
    bool(false)
    }

Edit to add code

//create new opp fields
$newOpportunityFields = new StdClass();

//set fields
$newOpportunityFields->Name = 'test - delete me';
$newOpportunityFields->StageName = 'Fully Executed Contract Received';
$newOpportunityFields->CloseDate = date('c', strtotime( $currentOpportunity->CloseDate));


//turn stdclass into array for the fields array
$newFields = json_decode(json_encode($newOpportunity), true);

//create Soap object for creation
$sObject = new SObject();
$sObject->fields = $newFields;
$sObject->type = 'Opportunity';

//send
$return  = $connection->create($sObject);
  • post your code. – superfell Nov 6 '14 at 15:34
  • what happens if you try to create the opportunity via the GUI? You might be missing an authorization or there might be another process (trigger, workflow) blanking out the fields again.. – Guy Clairbois Nov 6 '14 at 16:30
  • There is a workflow, however all required fields are entered. If i use the Gui to enter the Opportunity it works immediately. – h8a Nov 6 '14 at 19:16
1

The main problem I see here is that create() takes an array, rather than a single record. I'm also not sure why you're doing the stdclass -> JSON -> array transformation - just create the array directly. This code works for me:

$sObject = new SObject();
$sObject->fields = array(
    'Name' => 'test - delete me',
    'StageName' => 'Prospecting',
    'CloseDate' => '2014-12-31',
);
$sObject->type = 'Opportunity';

$response = $mySforceConnection->create(array($sObject));
  • Creating the array directly into the SObject does not work either. I get the same message. Is there a way on the Salesforce side to see the message as it comes in and find the point of failure? – h8a Nov 6 '14 at 18:59
  • Can you update your question with the current code? – metadaddy Nov 7 '14 at 1:26
  • 1
    After reviewing your code I found the issue. I was passing the $sObject directly into the create method, instead of passing an array containing the $sObject. I incorrectly assumed that you could pass a single sObject into the method without it being inside of an array Thanks for your help! – h8a Nov 8 '14 at 2:09
  • 1
    Now you have to change your username from h8a to <3a :-) – metadaddy Nov 10 '14 at 0:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.