+ Start a Discussion

Getting Null Field Values



I was wondering if I could get some guidance here.


I am setting up a new Visualforce work order input screen and am having issues.  Specifically...


1) A Master Object record value (Services_Type__c) is used to name each Work Order record. 

2) This Master Object record also has a corresponding numerical value that represents the duration required for each piece of work (Days_to_Complete__C). 

3) Each VF entry screen is comprised of three work order records.

4) For reasons not relevant to this discussion, I need to compute the largest value of the Days_to_Complete__C value for each three-record group - and place this value in the Longest_Component__C field for each member of the three-record group.


My problem is that I am seeing null values in the Longest_Component__C field for all records.  I am pretty sure my problem is that I am not using the getRecord or getParameters command...but I am confused as how to best approach things.


Also, I am using a custom controller.


Below is the relevant code...thanks in advance for any guidance.


LargestValue = 0;
for (Integer x = 0; x < 3; x++)
if(myList[x].Services_Type__r.Days_to_Complete__C > LargestValue)
LargestValue = myList[x].Services_Type__r.Days_to_Complete__C;
myList[x].Longest_Component__C = LargestValue;
insert myList; 





It does not make sense to me that you are getting a null value, because LargestValue is being initialized with 0. I do however have some recommendations:


  1. You need two separate for loops. One that calculates the Max and one that sets the Longest_Component__c for each record. Your current code will set item 1 to the max of (0, item 1), item 2 to the max of (0, item 1, item 2) and item 3 to the max of (0, item 1, item 2, item 3).
  2. I recommend using the Math.max method for setting the LargestValue variable.
  3. If the Days_to_Complete__c is not a required field, I recommend adding logic to handle cases where Days_to_Complete__c is null.




Thanks. I will give that a try

One note. The Days_to_Complete__c variable is not included in my VF code...so I was wondering if I needed to something in the controller to explicitly note this field.

Thanks again.