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

Issue with Datetime value when using <apex:dynamicComponent>
I am using the CreatedDate column to determine the age of a Case. Each case is displayed in a pageblock table row. The pageblocktable is being generateing using apex:dynamicComponent. The Apex code to generate the column in question looks like this:
.... Component.Apex.column col = new Component.Apex.column(); col.width = '125'; col.headerValue = 'Case Age'; Component.Apex.OutputText ot = new Component.Apex.OutputText(); ot.expressions.value = '{!TEXT(ROUND((NOW() - qc.CreatedDate) * 24, 0))&\'hrs \'&TEXT(ROUND(MOD(ROUND((NOW() - qc.CreatedDate) * 24,3),1)*60,0))&\'mins\'}'; col.childComponents.add(ot); ...
When I attempt to bring up the VF page, I get this message:
Incorrect parameter type for operator '-'. Expected Number, Date, DateTime, received Object
.... <apex:column headerValue="Case Age"> <apex:outputText value="{!TEXT(ROUND((NOW() - qc.CreatedDate) * 24, 0))&'hrs'&TEXT(ROUND(MOD(ROUND((NOW() - qc.CreatedDate) * 24, 3),1)*60,0))&'min'}"/> </apex:column> ...
...it works.
With the dynamically generated VF, seems as though the datetime is not being treated as a datetime. I tried wrapping CreatedDate in DATETIMEVALUE() but that did not work either.
Anyone have any ideas on this one?
Thanks
Hello,
TEXT, NOW methods don't work in apex. You need to use String.ValueOf method to convert date to string. Similarly for Now you can use system.now().
Please refer followings for list of methods available:
http://www.salesforce.com/us/developer/docs/dbcom_apex250/Content/apex_methods_system_string.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_System_Date_static_methods.htm
NOW() is not being used in Apex. Remember, this is dynamically generated VF. It is passed as a String to the VF page that is being generated by the Apex code and then evaluated in the VF page. That is why all those VF functions in the Apex code example are in quotes. In any case, the function NOW() is not the problem...I am pretty sure that the things is blowing up on the CreatedDate field.
I don't know why what you're trying to do doesn't work. But I have an idea for an alternate implementation.
If your iteration variable "qc" was a wrapper class instead of a Case, you could perform the Case Age calculation in your controller using Apex.
Something like:
The pageBlockTable would iterate over a list of CaseWrapper instances. All the record fields would be accessed with "qc.theCase.<field>", and the Case Age would be "qc.caseAge".
Let me know what you think of this idea.
-Glyn