You need to sign in to do that
Don't have an account?

How do you assign to a Picklist programmatically?
I'm trying to upsert an Object that has required Picklist Fields.
I've written code that constructs a list of Ooportunities objects that I want to upsert in an Apex controller:
public List<Opportunity> DonationData = new List<Opportunity>(); upsert DonationData;
But there's a required Picklist field called Stage in the Opportunity Object and I must load this field or the upsert operation fails with this error:
Error: Required fields are missing: [Opportunity Name, Stage]
The Stage field is not important to me, and so. I have been trying put stub data in it:
* Integers 0 & 1 don't work
* String 'Close Won' doesn't work
There is no PickList object, to my knowledge, so there are no Picklist methods.
QUESTION: How do you assign a picklist value programmatically?
Picklists values are stored as String in the system. So assgning a string should work. Along with the stage dield there are several other fields which are mandatory. You need to set them too.
And you list is also not containing any data that shpould be updated?????
in the provided code you list DontationData is empty.
My discussion of upserting only misled & confused everyone, and it is not really relevant. Apologies!!
I was getting compiler errors when trying to assign to the Stage Picklist:
And I assumed my problem was a data type mismatch. But it was simply that I was using the wrong API name for the Stage field. I should have written: op.StageName = "Closed Won" instead of op.Stage = "Closed Won".
Sorry for the wild goose chase. This is what happens when a 60 year old who hasn't programmed in 15 years tries his hand at a technical role in a new technology.
Thanks to all of you, especially Saurabh Dhoble, for clarifying that I ought to be able to assign a string to the StageName Picklist field. Wouldn't hurt if that were mentioned in the documentation page for the Opportunities Object.