3

I searched a couple of days and didn't find how can i put my custom fields in standard SalesForce object (Account, Lead, Opportunity etc...). I found only info about metadata API described here, but it explains inserting new metadata only on custom objets. I found this code too, but it works only for custom objects too. Does anybody knows more about this stuff? Thanks.

EDIT: Here is final working code for those who can't find example.

// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.com password
define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');
require_once (SOAP_CLIENT_BASEDIR.'/SforceMetadataClient.php');
require_once ('../userAuth.php');
try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
  $loginResult = $mySforceConnection->login($USERNAME, $PASSWORD);
  $myMetadataConnection = new SforceMetadataClient(SOAP_CLIENT_BASEDIR.'/metadata.wsdl.xml', $loginResult, $mySforceConnection);
  $customField = new SforceCustomField();
  $customField->setFullName('Account.MyCustomFieldb__c');
  $customField->setDescription('Description of New Field');
  $customField->setLabel('My Custom Field Label');
  $customField->setType('Text');
  $customField->setLength(255);
  print_r($myMetadataConnection->create($customField));
} catch (Exception $e) {
  echo $myMetadataConnection->getLastRequest();
  echo $e->faultstring;
}

1 Answer 1

3

You would create populate a CustomField structure, setting the fullName property based on the standard object you want to add it to, e.g. Account.rating__c and then pass that to the create metadata API call. I don't know about PHP, bu there's an example in .NET here.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried it but it rises an Error "The custom object name must finish with __c".
Sounds like you're sending a CustomObject and not just a CustomField.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.