certinia / apex-mdapi

Apex Wrapper for the Salesforce Metadata API
BSD 3-Clause "New" or "Revised" License
684 stars 975 forks source link

Question: How to get dependent picklist values? #93

Closed douglascayers closed 9 years ago

douglascayers commented 9 years ago

Hello! This is a great API by the way!

I have two picklist fields on a custom object with a dependency between them. Picklist A controls Picklist B. I also have multiple record types on this custom object and subsets of each picklist's value are assigned to each record type.

Using the MetadataService, I am having trouble identifying which values in Picklist B are assigned to a controlling value in Picklist A. I am trying to reproduce the dependent picklist behavior of standard page layouts in my custom visualforce page. The controlling picklist behavior works when I'm on the standard page layout of the custom object but I'm not sure how to implement this same behavior using the MetadataService.

I notice that the MetadataService.PicklistValue class has a property controllingFieldValues but the value is always null for me.

I have tried getting the custom field Picklist A and Picklist B then iterating through customField.picklist.picklistValues to look at the controllingFieldValues property of each picklist entry and in both cases the value is always null.

Thanks!

afawcett commented 9 years ago

Can you check the debug log for the XML response and see what it looks like? Just want to rule out a marshalling issue.

douglascayers commented 9 years ago

Sure, in the MetadataService.readMetadata(..) method I put a System.debug( response__x ) just after line 9653 to print out the response from the WebServiceCallout.invoke(..) call.

I have pasted the debug output from that statement below, I apologize for the formatting. I have marked bold a single picklist value response in hopes that makes reading the snippet easier. You can search for controllingFieldValues= and see that it prints null all the way down.

I appreciate your help!

07:51:56:261 USER_DEBUG [9654]|DEBUG|response=readRecordTypeResponse_element:[apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), field_order_type_info=(result), result=ReadRecordTypeResult:[apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), field_order_type_info=(records), records=(RecordType:[Metadata.fullName=null, active=true, active_type_info=(active, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), businessProcess=null, businessProcess_type_info=(businessProcess, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), compactLayoutAssignment=null, compactLayoutAssignment_type_info=(compactLayoutAssignment, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), description=Define relationship how one contact relates to one account. For example, "Employee, Patient, etc.", description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, active, businessProcess, compactLayoutAssignment, description, label, picklistValues), fullName=Associationc.Contact_to_Account, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), label=Contact-to-Account, label_type_info=(label, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), picklistValues=(RecordTypePicklistValue:[apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), field_order_type_info=(picklist, values), **picklist=Rolec, picklist_type_info=(picklist, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), values=(PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Baseball Coach, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)]**, PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Basketball Coach, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Cheerleading Coach, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Football Coach, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Gold Coach, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Lacrosse Coach, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Primary, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Secondary, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Soccer Coach, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Softball Coach, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], ...), values_type_info=(values, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false)], RecordTypePicklistValue:[apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), field_order_type_info=(picklist, values), picklist=Serves_As__c, picklist_type_info=(picklist, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), values=(PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Athletic Trainer, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Coach, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Employee, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Employer Contact, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Patient, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Physician, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Principal, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Student, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Superintendent, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], PicklistValue:[Metadata.fullName=null, allowEmail=null, allowEmail_type_info=(allowEmail, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), apex_schema_type_info=(http://soap.sforce.com/2006/04/metadata, true, false), closed=null, closed_type_info=(closed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), color=null, color_type_info=(color, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), controllingFieldValues=null, controllingFieldValues_type_info=(controllingFieldValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), converted=null, converted_type_info=(converted, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), cssExposed=null, cssExposed_type_info=(cssExposed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), default_x=false, default_x_type_info=(default, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false), description=null, description_type_info=(description, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), field_order_type_info=(fullName, allowEmail, closed, color, controllingFieldValues, converted, cssExposed, default_x, description, forecastCategory, ...), forecastCategory=null, forecastCategory_type_info=(forecastCategory, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), fullName=Team Doctor, fullName_type_info=(fullName, http://www.w3.org/2001/XMLSchema, string, 0, 1, false), highPriority=null, highPriority_type_info=(highPriority, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), probability=null, probability_type_info=(probability, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reverseRole=null, reverseRole_type_info=(reverseRole, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), reviewed=null, reviewed_type_info=(reviewed, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false), type=PicklistValue, type_att_info=(xsi:type), won=null, won_type_info=(won, http://soap.sforce.com/2006/04/metadata, null, 0, 1, false)], ...), values_type_info=(values, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false)]), picklistValues_type_info=(picklistValues, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false), type=RecordType, type_att_info=(xsi:type)]), records_type_info=(records, http://soap.sforce.com/2006/04/metadata, null, 0, -1, false)], result_type_info=(result, http://soap.sforce.com/2006/04/metadata, null, 1, 1, false)]

afawcett commented 9 years ago

Yeah this points to an actual issue with the underlying Salesforce Metadata API rather than the wrapper itself. Did you happen to see XML in the Debug log at all? I sometimes find depending on the tool you run the platform omits this. The reason i ask is if you can get the XML sent and receive it becomes much easier to see via XML Pretty print tools what is being sent and received and also then if needed past into a Salesforce Case for them to review (they will find you submitting steps to reproduce via Apex MD API a distraction). Can you see if you can get XML from your debug logs? If you want to dump your Apex code here (the relavant bits) i'll also try and spot what might be going on?

douglascayers commented 9 years ago

I do not see any XML in the debug logs. I have Callouts and Apex set to FINEST. I will put together a simple example and post here too. Thanks

douglascayers commented 9 years ago

OK, after some more research here is my conclusion: the controllingFieldValues property on the PicklistValue metadata is not populated on the list of picklist values retrieved for RecordType (e.g. recordType.picklistValues[0].values[0].controllingFieldValues); however, they are populated on the list of picklist values retrieved for CustomField (e.g. customField.picklist.picklistValues[0].controllingFieldValues).

Unless that is a bug by the Metadata API, then to reproduce the dependent picklist behavior via custom code requires you to first query the picklist values from the custom field so you know the controlling field and controlling field values. Then you must apply two filters in code to narrow that list down. First, filter out any that aren't assigned to the intended record type. Second, for each picklist value assigned to the record type, iterate through the picklist values retrieved from the custom field so you can inspect if the "controlling value" (which you would have retrieved from the user as another input field or something) is a valid controlling value for the dependent picklist you want to display on the page. If it is then you can add that to your list to show the user, if it isn't then you know not to show it. Whew... quite a bit of work to reproduce the dependent picklist behavior!

Here's some instructions on how to reproduce the "controllingFieldValues" not showing up on picklists accessed from the RecordType metadata vs. showing up on picklists accessed from the CustomField metadata.

Setup

  1. In a dev org, create a field dependency on the Account object with Activec picklist controlling values in CustomerPriorityc picklist 1a. When Activec = Yes then let CustomerPriorityc include High 1b. When Activec = No then let CustomerPriorityc include Low
  2. Create an Account record type called Record_Type_A and allow all values for Activec be available but only allow CustomerPriorityc to have High and Low (exclude Medium)
  3. Verify intended behavior by creating a new account record. When Activec = Yes then CustomerPriorityc should allow you to choose High.
  4. Run the below apex snippet to see that controllingFieldValues metadata property is printed from picklist values retrieved via CustomField but are null when retrieved via RecordType
// Create service
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

// Read Custom Field
MetadataService.CustomField customField = (MetadataService.CustomField) service.readMetadata(
    'CustomField', new String[] { 'Account.CustomerPriority__c' }
).getRecords()[0];

System.debug( customField );

// Print each picklist value
MetadataService.PicklistValue[] picklistValues = customField.picklist.picklistValues;
for ( MetadataService.PicklistValue pk : picklistValues ) {
    System.debug( pk );
}

// Read Record Type
MetadataService.RecordType recordType = (MetadataService.RecordType) service.readMetadata(
    'RecordType', new String[] { 'Account.Record_Type_A' }
).getRecords()[0];

System.debug( recordType );

// Print each picklist value
MetadataService.RecordTypePicklistValue[] recordTypePicklistValues = recordType.picklistValues;
for ( MetadataService.RecordTypePicklistValue rtpk : recordTypePicklistValues ) {
    if ( 'CustomerPriority__c' == rtpk.picklist ) {
        for ( MetadataService.PicklistValue pk : rtpk.values ) {
            System.debug( pk );
        }
    }
}   
douglascayers commented 9 years ago

Using SOAP UI, here is the XML response for reading the CustomField and RecordType metadata in the above examples.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <readMetadataResponse>
         <result>
            <records xsi:type="CustomField">
               <fullName>Account.CustomerPriority__c</fullName>
               <externalId>false</externalId>
               <label>Customer Priority</label>
               <picklist>
                  <controllingField>Active__c</controllingField>
                  <picklistValues>
                     <fullName>High</fullName>
                     <controllingFieldValues>Yes</controllingFieldValues>
                     <default>false</default>
                  </picklistValues>
                  <picklistValues>
                     <fullName>Low</fullName>
                     <controllingFieldValues>No</controllingFieldValues>
                     <default>false</default>
                  </picklistValues>
                  <picklistValues>
                     <fullName>Medium</fullName>
                     <default>false</default>
                  </picklistValues>
                  <sorted>false</sorted>
               </picklist>
               <trackFeedHistory>false</trackFeedHistory>
               <type>Picklist</type>
            </records>
         </result>
      </readMetadataResponse>
   </soapenv:Body>
</soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns="http://soap.sforce.com/2006/04/metadata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <readMetadataResponse>
         <result>
            <records xsi:type="RecordType">
               <fullName>Account.Record_Type_A</fullName>
               <active>true</active>
               <label>Record Type A</label>
               <picklistValues>
                  <picklist>AccountSource</picklist>
                  <values>
                     <fullName>Other</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Partner Referral</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Phone Inquiry</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Purchased List</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Web</fullName>
                     <default>false</default>
                  </values>
               </picklistValues>
               <picklistValues>
                  <picklist>Active__c</picklist>
                  <values>
                     <fullName>No</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Yes</fullName>
                     <default>false</default>
                  </values>
               </picklistValues>
               <picklistValues>
                  <picklist>CustomerPriority__c</picklist>
                  <values>
                     <fullName>High</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Low</fullName>
                     <default>false</default>
                  </values>
               </picklistValues>
               <picklistValues>
                  <picklist>Industry</picklist>
                  <values>
                     <fullName>Agriculture</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Apparel</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Banking</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Biotechnology</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Chemicals</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Communications</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Construction</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Consulting</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Education</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Electronics</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Energy</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Engineering</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Entertainment</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Environmental</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Finance</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Food %26 Beverage</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Government</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Healthcare</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Hospitality</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Insurance</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Machinery</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Manufacturing</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Media</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Not For Profit</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Other</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Recreation</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Retail</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Shipping</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Technology</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Telecommunications</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Transportation</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Utilities</fullName>
                     <default>false</default>
                  </values>
               </picklistValues>
               <picklistValues>
                  <picklist>Ownership</picklist>
                  <values>
                     <fullName>Other</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Private</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Public</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Subsidiary</fullName>
                     <default>false</default>
                  </values>
               </picklistValues>
               <picklistValues>
                  <picklist>Rating</picklist>
                  <values>
                     <fullName>Cold</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Hot</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Warm</fullName>
                     <default>false</default>
                  </values>
               </picklistValues>
               <picklistValues>
                  <picklist>SLA__c</picklist>
                  <values>
                     <fullName>Bronze</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Gold</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Platinum</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Silver</fullName>
                     <default>false</default>
                  </values>
               </picklistValues>
               <picklistValues>
                  <picklist>Type</picklist>
                  <values>
                     <fullName>Channel Partner %2F Reseller</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Customer - Channel</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Customer - Direct</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Installation Partner</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Other</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Prospect</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Technology Partner</fullName>
                     <default>false</default>
                  </values>
               </picklistValues>
               <picklistValues>
                  <picklist>UpsellOpportunity__c</picklist>
                  <values>
                     <fullName>Maybe</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>No</fullName>
                     <default>false</default>
                  </values>
                  <values>
                     <fullName>Yes</fullName>
                     <default>false</default>
                  </values>
               </picklistValues>
            </records>
         </result>
      </readMetadataResponse>
   </soapenv:Body>
</soapenv:Envelope>
douglascayers commented 9 years ago

Ok, according to my hypothesis earlier, the below snippet will correctly determine the list of picklist values of a dependent field based on a value selected in the controlling field. In this snippet, I've hardcoded that the Account.Active__c picklist (controlling field) has a selected value of Yes and therefore, per the above example setup, the only appropriate value to show the user for Account.CustomerPriority__c will be High.

// Create service
MetadataService.MetadataPort service = new MetadataService.MetadataPort();
service.SessionHeader = new MetadataService.SessionHeader_element();
service.SessionHeader.sessionId = UserInfo.getSessionId();

// Read Custom Field
MetadataService.CustomField customField = (MetadataService.CustomField) service.readMetadata(
    'CustomField', new String[] { 'Account.CustomerPriority__c' }
).getRecords()[0];

System.debug( 'custom field = ' + customField );

// Print each picklist value
for ( MetadataService.PicklistValue pk : customField.picklist.picklistValues ) {
    System.debug( pk );
}

// Read Record Type
MetadataService.RecordType recordType = (MetadataService.RecordType) service.readMetadata(
    'RecordType', new String[] { 'Account.Record_Type_A' }
).getRecords()[0];

System.debug( 'record type = ' + recordType );

Map<String, MetadataService.PicklistValue> valuesMap = new Map<String, MetadataService.PicklistValue>();
for ( MetadataService.PicklistValue pk : customField.picklist.picklistValues ) {
    valuesMap.put( pk.fullName, pk );
}

System.debug( 'values map = ' + valuesMap );

// At the end, this list will contain only those picklist values
// that are both assigned to the RecordType and satisfy the
// picklist dependency of the controlling field's value
List<MetadataService.PicklistValue> filteredDependentValues = new List<MetadataService.PicklistValue>();

// Of all the picklist values setup for the Account.CustomerPriority__c field,
// iterate over the values explicitly assigned to the Account.Record_Type_A record type.
for ( MetadataService.RecordTypePicklistValue rpk : recordType.picklistValues ) {
    if ( 'CustomerPriority__c' == rpk.picklist ) {
        for ( MetadataService.PicklistValue pk : rpk.values ) {

            // Since the Metadata API does not provide the 'controllingFieldValues' property
            // on the PicklistValues of the RecordType metadata response, we must now look that data up
            // from the map we built earlier of the PicklistValues of the CustomField metadata response
            MetadataService.PicklistValue value = valuesMap.get( pk.fullName );

            // In this example the controlling field, Account.Active__c, has selected value of 'Yes'
            // so if the PicklistValue entry we're iterating over right now is controlled by that value
            // then we'll add it to our filtered list, otherwise we must ignore it
            if ( new Set<String>( value.controllingFieldValues ).contains( 'Yes' ) ) {
                filteredDependentValues.add( value );
            }

        }
    }
}

System.debug( 'Filtered, Dependent Values = ' + filteredDependentValues );
afawcett commented 9 years ago

Wow @DouglasCAyers amazing research! And yes not easy to obtain Record Type filtered Picklist values, i feel an Idea brewing, one which i'd certainly give my vote to! Meanwhile it seems you've answered your own question very well here.

I think its worth including in MetadataServicesExample.cls personally, i can either move it or if you want to do a PR thats fine. Either way, thanks for what is a great post here i'm sure others will surely appreciated it in the future, thanks for sharing!

douglascayers commented 9 years ago

Thanks for the feedback Andy! It was a fun weekend project for sure. I'd love to submit a pull request to add this to the MetadataServiceExample.cls :)

Thanks for helping guide me through the issue.

codewerk commented 7 years ago

CustomField is NULL. Can anyone suggest a resolution for this code snippet below? The field exists and I can create/update using the Apex Metadata API just fine.

// Read Custom Field MetadataService.CustomField customField = (MetadataService.CustomField) service.readMetadata( 'CustomField', new String[] { 'Account.CustomerPriority__c' } ).getRecords()[0];

afawcett commented 7 years ago

@codewerk You cannot retrieve CustomField's on their own, you have to retrieve the CustomObject first.

PavloShchur commented 5 years ago

MetadataService.CustomField does not have 'picklist' variable. I mean getDependentPicklistValues() method.