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
OptimusPrimeOptimusPrime 

updatin default value on a custom picklist field

Hello all,

I am a newbie at Apex programming. I'd like to update/set the default value on a custom picklist field. how do I go about that?

Thanks in advance
mtbclimbermtbclimber
There are two possible explanations depending on what you want to do here:

1) If you are talking about the default value for a record you can do that declaratively under setup. If you want to override what the user submits (say if it's null) with a value that is based on other attributes on the record being submitted then you would do this in a before trigger on insert or update (or both) of the object in question

2) If you are talking about using apex to change the default value for the picklist field definition (i.e. under setup) itself then that is not possible.
OptimusPrimeOptimusPrime
Thanks for your help in clarifying.

I do have one other question,

So I am trying to create a new object, custom object initial assessment, through ajax because saleforce enterprise does not have trigger functionality yet. However, when i do the following;

initialAssmt.Case__c = document.getElementById("caseNumber").value;

I get error:

failed to create initial assessment {error:{fields:'Case__c', message:'Case: id value of incorrect type: 00001027', statusCode:'MALFORMED_ID',}, id:null, success:'false',}

00001027 is the case number, not id. But the custom field Case in the custom object initial assessment is of data field type lookup. So, I would assume that we provide the case number for to lookup the id.
mtbclimbermtbclimber
Can you please post this question in the AJAX Toolkit & Scontrols board?

Thanks,