How to Create New Salesforce Custom Object Using PHP Script

We can creates custom object in salesforce using PHP Script.


<?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;
}

?>

You can find the Basic Tutorials about PHP and Salesforce Implementation using Below URL

http://theblogreaders.com/integration-between-salesforce-and-php

Written by 

I am Sakthivel Madesh, a certified Salesforce Advanced Developer & Administrator working on Salesforce Technology since 2011. I am currently working in Techforce Services as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 15x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead 5x Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply