You need to sign in to do that
Don't have an account?
Amoun777
Trying to instantiate a custom object with a default value in a field
I may be missing something simple but I cannot seem to get a default Number value to appear in an object I instantiate in apex. The value is always == null. My variable is Mileage_Rate__c and in my org the default value = 0.58. When I create an instance using the following code this value is always null. I do not want to hardcode this in my apex class. Any suggestions?
apex:
Expense_Report = new Expense_Report__c(Status__c = 'Unsaved');
...
if(Expense_Report.Mileage_Rate__c == null){
// This code will always execute}
Thanks in advance for any help on this!
Adam
Hi,
Once you saved the record to the database then only the auto number field will be not null.
Until and unless you save it to the database it will be always null.