You need to sign in to do that
Don't have an account?
Vishal Gaddi6
Need a Code to Create Custom Object via PHP Script
Hey
I am using PHP to connect to Salesforce API and connection is established successfully. I have done the Insertion n Query part over Standard and Custom Objects.
I need some code to create a Custom Object in Salesforce via PHP Script.
If anyone can help,.....
Hi the code below creates a custom object in salesforce.
<?php
require_once('soapclient/SforcePartnerClient.php');
require_once('soapclient/SforceMetadataClient.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection('soapclient/Partnetwsdl.xml');
$loginResult = $mySforceConnection->login('xxxx@xx.com', 'cc20127B8fw0x92YerGiV4zak5ucMc');
$myMetadataConnection = new SforceMetadataClient('soapclient./metadata.xml', $loginResult, $mySforceConnection);
//Create object
$customObject = new SforceCustomObject();
$customObject->fullName = 'CustomObjFromPHP__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");
$customField = new SforceCustomField();
$customField->setFullName('MyCustomFieldb__c');
$customField->setDescription('Description of New Field');
$customField->setLabel('My Custom Field Label');
$customField->setType('Text');
$customObject->nameField = $customField;
$customObject->pluralLabel = 'My Custom Objs from PHP';
$customObject->sharingModel = SHARING_MODEL_READWRITE;
print_r($myMetadataConnection->create($customObject));
} catch (Exception $e) {
echo $myMetadataConnection->getLastRequest();
echo $e->faultstring;
}
?>
Regards,
Nishna
All Answers
Hi Vishal,
For the REST API, Create/Read/Update/Delete are all covered in this article - http://developer.force.com/cookbook/recipe/interact-with-the-forcecom-rest-api-from-php
For the SOAP API, there is sample code here - http://wiki.developerforce.com/index.php/PHP_Toolkit_20.0_Samples
Cheers,
Pat
Hey Pat !!! Thanx for replying...
Can u refer me some code to use Bulk API as my website would be public and there will be so many API Calls to the server.
Hey Pat, I found the following code to create a Custom Object in JAVA.
}
Hi the code below creates a custom object in salesforce.
<?php
require_once('soapclient/SforcePartnerClient.php');
require_once('soapclient/SforceMetadataClient.php');
try {
$mySforceConnection = new SforcePartnerClient();
$mySoapClient = $mySforceConnection->createConnection('soapclient/Partnetwsdl.xml');
$loginResult = $mySforceConnection->login('xxxx@xx.com', 'cc20127B8fw0x92YerGiV4zak5ucMc');
$myMetadataConnection = new SforceMetadataClient('soapclient./metadata.xml', $loginResult, $mySforceConnection);
//Create object
$customObject = new SforceCustomObject();
$customObject->fullName = 'CustomObjFromPHP__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");
$customField = new SforceCustomField();
$customField->setFullName('MyCustomFieldb__c');
$customField->setDescription('Description of New Field');
$customField->setLabel('My Custom Field Label');
$customField->setType('Text');
$customObject->nameField = $customField;
$customObject->pluralLabel = 'My Custom Objs from PHP';
$customObject->sharingModel = SHARING_MODEL_READWRITE;
print_r($myMetadataConnection->create($customObject));
} catch (Exception $e) {
echo $myMetadataConnection->getLastRequest();
echo $e->faultstring;
}
?>
Regards,
Nishna
Hi,
Its not working for me,if i have to do any changes please let me know.
Hi ruddra,
What are you trying to do? What code are you using? How is it not working? What error do you see?
Cheers,
Pat