I have successfully been able to add a new value to the Picklist for Lead.LeadSource
using the PHP Toolkit on the MetaData API using the following:
$sfm = new SforceMetadataClient(...) $obj = new SforceCustomObject(); $obj->currentName = 'Lead.LeadSource'; $obj->metadata = new SforceCustomField(); $obj->metadata->fullName = 'Lead.LeadSource'; $obj->metadata->type = 'Picklist'; $obj->metadata->picklist = new stdClass(); $obj->metadata->picklist->sorted = false; $obj->metadata->picklist->picklistValues = array(); $obj->metadata->picklist->picklistValues[0] = new stdClass(); $obj->metadata->picklist->picklistValues[0]->default = false; $obj->metadata->picklist->picklistValues[0]->fullName = 'Test Source'; $result = $sfm->update($obj);
This however doesn’t filter down to any of the RecordTypes.
I’ve now spent several hours to rework the above code to try and get it to update the individual record types that extend Lead. I have also tried to adapt the Java code provided for RecordType Object into PHP with no success.
Is there anyway to achieve what I am trying to do?
(If you know the PHP that would be really handy too)
Thanks
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Phil, what you are doing in your code is adding available Picklist values to the LeadSource
field. To actually assign combinations of Picklist values to different Lead RecordTypes, you will need to add these Picklist field values to the various Lead record types. To do this you will have to modify each Lead RecordType’s valid Picklist values.
The chain for this is:
- Get the
Lead
metadata object. - Get its
RecordTypes
property, a list ofRecordType
objects for theLead
object. - Find the appropriate
RecordType
from that list. - Get this
RecordType
‘sPicklistValues
property, a list ofRecordTypePicklistValue
objects. - Modify the
RecordTypePicklistValue
records as appropriate, adding values to eachRecordTypePicklistValue
object’svalues
property.
See the Metadata API Documentation for the RecordType object for more detail on the objects involved here.
Also, you may need to make the appropriate Lead RecordTypes available to different Profiles.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0