function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
D-PriceD-Price 

Update Custom Picklist on Account using API

I am trying to update (add a value to)  a custom picklist that is on our Account. I'm getting confused by Enterprise route and the Metadata route.

 

This post seems close, but I don't want to rename a field just to add a new value:

http://boards.developerforce.com/t5/Java-Development/Does-the-Metadata-API-update-feature-work-with-Picklists/m-p/61641/highlight/true#M4847

 

Here's the code I'm working with using an Enterprise connection:

 

public void updatePicklistSample(EnterpriseConnection connection)
{
	try
	{
		DescribeSObjectResult describeSObjectResult = connection.describeSObject("Account");
		Field[] fields = describeSObjectResult.getFields();
		// create a map of all fields for later lookup
		Map<String, Field> fieldMap = new HashMap<>();
		for(Field field : fields)
			fieldMap.put(field.getName(), field);

		for(Field field : fields)
		{
			// check whether this is my picklist
			if(field.getName().equals("My_Custom_Picklist__c"))
			{
				ArrayList<PicklistEntry> pickListValuesArrayList = new ArrayList<>();
				for(PicklistEntry picklistEntry : field.getPicklistValues())
					pickListValuesArrayList.add(picklistEntry);

				final PicklistEntry entry = new PicklistEntry();
				entry.setActive(true);
				entry.setDefaultValue(false);
				entry.setValue("9999");
				entry.setLabel("9999");
				pickListValuesArrayList.add(entry);
					final PicklistEntry[] plv = pickListValuesArrayList.toArray(new PicklistEntry[pickListValuesArrayList.size()]);
				field.setPicklistValues(plv);
			}
		}
		// What to update here?
		connection.update(????);
	}
	catch(ConnectionException ce)
	{
		fail("Connection failed: " + ce);
	}
}

 I'm just not sure what SObject I need to update.

 

I've also seen this sample that creates a new picklist, but I just want to update a custom field on Account:

http://www.salesforce.com/us/developer/docs/api_meta/index_Left.htm#StartTopic=Content/meta_picklist.htm

 

Does anyone have a clear example on how to do this? Any suggestions?

 

Thanks,

Derek