You need to sign in to do that
Don't have an account?
meyerd
metadata add Picklist values and retain/set alpha sort. setSorted(true)?
- Starting with a picklist that is sorted alpha “ Sort values alphabetically, not in the order entered.”
- V19 of the metadata wsdl
1) add a value through the metadata api.
2) add a value through the metadata api and setSorted(true); to the pl in the code.
In both 1) and 2) this value shows as the first value even though by alpha it would not be. Suggestions?
System.out.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ "); long waitTimeMilliSecs = 1000; String objectName = "MyObject__c"; String fieldName = "MyPickListField__c"; String fieldLabel = "MyPickListField"; HashSet<String> ValuesToProcess = new HashSet<String>(); ValuesToProcess.add("NewPickListValue"); CustomField field = new CustomField(); field.setFullName(objectName + "." + fieldName); field.setType(FieldType.Picklist); field.setLabel(fieldLabel); Picklist PicklistToManipulate = new Picklist(); PicklistValue tmpPicklistValue = new PicklistValue(); String toAdd; Integer i = 0; Iterator<String> processIterator = ValuesToProcess.iterator(); PicklistValue[] allPicklistValues = new PicklistValue[ValuesToProcess.size()]; while (processIterator.hasNext()) { toAdd = processIterator.next(); System.out.println("to add " + toAdd); tmpPicklistValue = new PicklistValue(); tmpPicklistValue.setFullName(toAdd); allPicklistValues[i++] = tmpPicklistValue; } PicklistToManipulate.setPicklistValues(allPicklistValues); //setSorted? System.out.println("setSorted(true)"); PicklistToManipulate.setSorted(true); field.setPicklist(PicklistToManipulate); UpdateMetadata updateMetadata = new UpdateMetadata(); updateMetadata.setMetadata(field); updateMetadata.setCurrentName(objectName + "." + fieldName); AsyncResult[] ars; try { ars = metadatabinding.update(new UpdateMetadata[] { updateMetadata }); AsyncResult asyncResult = ars[0]; while (!asyncResult.isDone()) { Thread.sleep(waitTimeMilliSecs); // double the wait time for the next iteration waitTimeMilliSecs *= 2; asyncResult = metadatabinding.checkStatus(new String[] { asyncResult.getId() })[0]; System.out.println("Status is: " + asyncResult.getState()); } if (asyncResult.getState() != AsyncRequestState.Completed) { throw new Exception(asyncResult.getStatusCode() + " msg: " + asyncResult.getMessage()); } } catch (Exception e) { e.printStackTrace(); }
SFDC applied patch. works now.