3

I'm using the PHP Toolkit for integrating a web application with my Salesforce account. I have this custom object:

Individual__Choice__c

that contains this custom Picklist:

Primary_Option__c

This Picklist currently has 15 or so options and I'd like to add a 16th. I've looked here and here and attempted to modify for my own use as follows:

$sfConnection = new SforceEnterpriseClient();
$sfConnection->createConnection(ENTERPRISE_WSDL);
$loginResult = $sfConnection->login(USERNAME , PASSWORD . TOKEN);
$sfMetadataConnection = new SforceMetadataClient(METADATA_WSDL, $loginResult, $sfConnection);

$customField = new SforceCustomField();
$customField->setFullName('Individual_Choice__c.Primary_Option__c');
$customField->setDescription('New Option Field');
$customField->setLabel('New Label');
$customField->setType('Picklist');
$sfMetadataConnection->create($customField);

But to no avail. I get this error:

Function ("create") is not a valid method for this service

I've also tried:

$sfConnection = new SforceEnterpriseClient();
$sfConnection->createConnection(ENTERPRISE_WSDL);
$loginResult = $sfConnection->login(USERNAME , PASSWORD . TOKEN);
$sfMetadataConnection = new SforceMetadataClient(METADATA_WSDL, $loginResult, $sfConnection);

$obj = new SforceCustomObject();
$obj->currentName = 'Individual_Choice__c.Primary_Option__c'';
$obj->metadata = new SforceCustomField();
$obj->metadata->fullName = 'Individual_Choice__c.Primary_Option__c'';
$obj->metadata->type = 'Picklist';
$obj->metadata->picklist = new stdClass();
$obj->metadata->picklist->picklistValues = [];
$obj->metadata->picklist->picklistValues[0] = new stdClass();
$obj->metadata->picklist->picklistValues[0]->label = 'New Label';
$obj->metadata->picklist->picklistValues[0]->value = 'New Value';

$result = $sfMetadataConnection->update($obj);

But, again, I get a similar error:

Function ("update") is not a valid method for this service

I know I'm able to successfully make the metadata client connection because if I var_dump at that point in my code I get a valid object.

Any idea of how I can properly accomplish this using PHP?

2 Answers 2

3

From what I can see you're using the metadata API to create/update fields, which is not supported via that API. In cases where you need to interact with your org's objects, apex classes etc. Salesforce offers a different kind of API called the Tooling API. Find out more

0

You have to change create to createMetadata and update to updateMetadata. It looks like force.com toolkit for php wasn't maintained as future api versions were released and names changed. create and update were deprecated.

Here's where you change the create:

https://github.com/developerforce/Force.com-Toolkit-for-PHP/blob/master/soapclient/SforceMetadataClient.php#L133

you might also want to consider using upsertMetadata

Docs: https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_crud_based_calls_intro.htm

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .