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) {
  string(11) "Opportunity"
  object(stdClass)#3 (48) {
    string(18) "xxxxx"
    string(18) "xxxxx"
    string(18) "xxxxx"
    string(25) "2014-03-18T00:00:00-04:00"
    string(25) "Closed"
    string(16) "test - delete me"

Return message from API

   object(stdClass)#17 (3) {
    array(1) {
      object(stdClass)#18 (3) {
        array(3) {
          string(4) "Name"
          string(9) "StageName"
          string(9) "CloseDate"
        string(57) "Required fields are missing: [Name, StageName, CloseDate]"
        string(22) "REQUIRED_FIELD_MISSING"

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';

$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.. 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

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.