4

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

5

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:

  1. Get the Lead metadata object.
  2. Get its RecordTypes property, a list of RecordType objects for the Lead object.
  3. Find the appropriate RecordType from that list.
  4. Get this RecordType's PicklistValues property, a list of RecordTypePicklistValue objects.
  5. Modify the RecordTypePicklistValue records as appropriate, adding values to each RecordTypePicklistValue object's values 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.

1
  • Thank so much. I had tried this path, but had thought I was going the wrong way. Having you re-assure me that I was on the right track I created a full set of Objects based on the API docs and manipulated the describeLayout response to meet my needs. Thanks again.
    – user934
    Nov 19 '12 at 19:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy