You need to sign in to do that
Don't have an account?
Lightning User
Creating object with metadata API
Hi, I'm getting this error (Cannot create child objects through
metadata create / update. The
CustomField must named 'MyObject__c.MyField1__c' be created separately)
when creating an object in salesforce. Anyone have an idea what the
problem is?
Code:
<—php header('P3P: CP=IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT'); require_once ('soapclient/SforcePartnerClient.php'); require_once ('soapclient/SforceHeaderOptions.php'); require_once ('soapclient/SforceMetadataClient.php'); echo "Begin Test Setup\r\n"; try { // Create the fixtures. $mySforceConnection = new SforcePartnerClient(); $mySoapClient = $mySforceConnection->createConnection('soapclient/partner.wsdl.xml'); $loginResult = $mySforceConnection->login('username', 'password'); $myMetadataConnection = new SforceMetadataClient('soapclient/metadata.wsdl.xml', $loginResult, $mySforceConnection); $customObject = new SforceCustomObject(); $customObject->fullName = 'MyObject__c'; $customObject->deploymentStatus = DEPLOYMENT_STATUS_DEPLOYED; $customObject->setDescription("A description"); $customObject->setEnableActivities(true); $customObject->setEnableDivisions(false); $customObject->setEnableHistory(true); $customObject->setEnableReports(true); $customObject->setHousehold(false); $customObject->setLabel("My Custom Obj from PHP"); $customField1 = new SforceCustomField(); $customField1->setFullName('MyCustomField__c'); $customField1->setDescription('Description of New Field'); $customField1->setLabel('My Custom Field Label'); $customField1->setType('Text'); $customField = new SforceCustomField(); $customField->setFullName('MyObject__c.MyField1__c'); $customField->setDescription('Test Picklist'); $customField->setLabel('Pij'); $customField->setLength(15); $customField->setType('Text'); $customField2 = new SforceCustomField(); $customField2->setFullName('MyObject__c.MyField2__c'); $customField2->setDescription('Test Picklist'); $customField2->setLength(15); $customField2->setLabel('Pif'); $customField2->setType('Text'); $customObject->nameField = $customField1; $customObject->pluralLabel = 'My Custom Objs from PHP'; $customObject->sharingModel = SHARING_MODEL_READWRITE; $array = array ($customField, $customField2); $customObject->setFields($array); print_r($myMetadataConnection->create($customObject)); } catch (Exception $e) { echo $myMetadataConnection->getLastRequest(); echo $e->faultstring; } –>
print_r($myMetadataConnection->create($customObject));
$customObject->setFields($array);
public function create($obj) {
$encodedObj->metadata = new SoapVar($obj, SOAP_ENC_OBJECT, 'CustomObject', $this->namespace);
return $this->sforce->create($encodedObj);
}
I try to spoof a field as an object (otherwise it complains some properties aren't set), but the fields won't show up in the table. I will post my updated code:
Message Edited by Gillberg on 05-19-2008 11:19 AM
Message Edited by Gillberg on 05-19-2008 12:15 PM