/
Handling Custom Picklists
Handling Custom Picklists
Values for custom Pick-list fields in Salesforce can be set as strings. The following example is for a built-in field, but the same approach will work for custom fields.
For the Account Rating picklist field the value can be set as follows:
/// <summary> /// Manually created enum to represent known picklist values /// </summary> public enum AccountRatings { Cold, Warm, Hot } [TestMethod] public void UpdatePicklistField() { SalesforceSession salesforceSession = SessionTest.GetActiveSession(); AccountService accountService = new AccountService(salesforceSession); // Retrieve an existing Account. Just get the required fields. Id existingAccountId = (Id)"00190000002G9cF"; Account account = accountService.GetByEntityId(existingAccountId, nmew SObjectField[] { Account.Fields.Id, Account.Fields.Rating}); string existingRating = account.InternalFields["Rating"]; // Example using internal fields to set a picklist value. // Would equally work for custom picklist fields. // account.InternalFields["Rating"] = "Hot"; account.InternalFields["Rating"] = AccountRatings.Cold.ToString(); SaveResult updateResult = accountService.UpdateEntity(account); Assert.IsTrue(updateResult.success); // Restore previous value using the generated property. account.Rating = existingRating; accountService.UpdateEntity(account); }