In salesforce phptoolkit how to get dynamic dropdown values
I want to know how can i retrieve values for a dropdown that's dynamic based on other field. For example : How do i get values for "Sub Category" if its dependent on "Category" dropdown.开发者_开发百科
Also wanted to know how can i find all fields for "Case" which are required in order to submit new "Case". I am trying to do this using phptoolkit but i found no good documentation on it.
PHP toolkit in essence is a WSDL SOAP wrapper so anything applicable to salesforce API web servce applies to PHP toolkit.
The following is a procedure to solve your problems (I dont have a PHP sample):
- call
describeSObject
to retrieve information about the object - Each field in
describesObjectResult.Fields
has three important properties for you,creatable
,nillable
anddefaultedOnCreate
. If createable and not nillable and not defaulted you must provide a value, this answers question #2 - if field type is picklist or multipcklist then fields'
picklistValues
contains a list ofPicklistEntry
elements. If picklist is dependent each entry contains a base64 encoded bitmap invalidFor
property. Each bit at position i is 0 or 1, corresponding to whether picklist entry is applicable for master picklist entry at position i. - You have to decode the bitmap and use it to determine for which master picklist entries this particular entry can be used. Unfortuantely for now its the only way.
I can give you a sample in javascript of how I did it (lstCategories
and lstSubcategories
are arrays of PickListEntry
), lstApplicableSubs
is created having the list of subcategories for every category. This should give you an approach to decoding:
var b64 = new sforce.Base64Binary("");
lstApplicableSubs = new Array(lstCategories.length);
for (var i = 0; i < lstApplicableSubs.length; i++) lstApplicableSubs[i] = new Array();
for (i = 0; i < lstSubCategories.length; i++)
{
var map = b64.decode(lstSubCategories[i].validFor);
for (var j = 0; j < lstCategories.length; j++)
{
var bits = map.charCodeAt(j >> 3);
if ((bits & (0x80 >> (j & 0x07))) != 0) lstApplicableSubs[j].push(lstSubCategories[i]);
}
}
精彩评论