You need to sign in to do that
Don't have an account?
Mike @ Partners
Add Product to Opportunity
I am trying to adda product to an opportunit that was just created. I came up with this code:
Code:
This code creats the opportunit then it is supose to add the correct product to the opportunit that was just created. The opportunit gets create but i get this error when it trys to add the product:
object(stdClass)#11 (3) { ["errors"]=> object(stdClass)#12 (3) { ["fields"]=> NULL ["message"]=> string(16) "assertion failed" ["statusCode"]=> string(17) "UNKNOWN_EXCEPTION" } ["id"]=> NULL ["success"]=> bool(false) }
Any ideas on where im going wrong?
thanks for the help.
Mike
Code:
$fieldsToCreate = array('Name'=>$OpName,'Type'=> $OpType,'LeadSource'=>$OpSource,'CloseDate'=>$PWDate,'StageName'=>$OpStage,'CampaignId'=>$CampaignId,'Amount'=>$BillAmount,'AccountId'=>$AccountId,'Public_Workshop__c'=>$POWid,'RecordTypeId'=>$RecordTypedID,'AccountId'=>$AccountId);
$sObject1 = new SObject();
$sObject1->fields = $fieldsToCreate;
$sObject1->type = 'Opportunity';
$updateRespons = $mySforceConnection->create(array($sObject1));
var_dump($updateRespons);
$updateResponsid = $updateRespons->id;
$fieldsToCreate2 = array('OpportunityId'=> $updateResponsid,'UnitPrice'=> $salesprice,'ProductId'=>'00j30000000mflNAAQ','PricebookEntryId'=>'01u30000000BCVIAA4','Quantity'=>$numAtten,'ServiceDate'=>$PWDate,'Location__c'=>$PWLocation,'Description'=>$lineDisc);
$sObject2 = new SObject();
$sObject2->fields = $fieldsToCreate2;
$sObject2->type = 'OpportunityLineItem';
$updateRespons2 = $mySforceConnection->create(array($sObject2));
var_dump($updateRespons2);
return $updateResponsid;
}
This code creats the opportunit then it is supose to add the correct product to the opportunit that was just created. The opportunit gets create but i get this error when it trys to add the product:
object(stdClass)#11 (3) { ["errors"]=> object(stdClass)#12 (3) { ["fields"]=> NULL ["message"]=> string(16) "assertion failed" ["statusCode"]=> string(17) "UNKNOWN_EXCEPTION" } ["id"]=> NULL ["success"]=> bool(false) }
Any ideas on where im going wrong?
thanks for the help.
Mike
object(stdClass)#8 (3) { ["errors"]=> NULL ["id"]=> string(18) "00660000007wSBBAA2" ["success"]=> bool(true) }
object(stdClass)#11 (3) { ["errors"]=> object(stdClass)#12 (3) { ["fields"]=> NULL ["message"]=> string(16) "assertion failed" ["statusCode"]=> string(17) "UNKNOWN_EXCEPTION" } ["id"]=> NULL ["success"]=> bool(false) }
The success var dump is the creation of the Opportunity. The second object , the one that is false is the where im trying to add the product.
Thanks for your help,
mike
I changed the code to this and i still get the error,
Code:
But i cant see why there would be a diifentes. All i did was change where the Pricing book id is with-in the array. When you say i need to 'set the priceBook on the opportunity first' Do you mean i need to run another call then run this call? What would that call look like?
Thank you for youe help,
Mike
Here are the IDs:
Code: Thanks for your help,
Mike
Message Edited by SimonF on 08-21-2006 10:21 AM
Thanks,
Mike
Here is the working code,
Mike
Code:
Thanks for the help,
Mike