You need to sign in to do that
Don't have an account?
Hopefully an easy one here guys....
I am trying to compare an apex variable defined as a DATE to my p.MVH_Month__c date value. (I only want to render the outputText on a control break on the data.)
<apex:variable var="LastMonth" value="{Date.parse('1990-01-01')}" />
<apex:repeat var="p" value="{!port}">
<apex:outputText rendered="{!if(LastMonth != p.MVH_Month__c,true,false)}">
.
.
.
The code won't compile it says "incorrect parameter type for operator <>. Expected TEXT received DATE.
If I change the code to this: <apex:outputText rendered="{!if(LastMonth != null,true,false)}"> it compiles so it looks like even though I am defining the <apex:variable LastMonth as a Date, the compiler is treating it like it is a String.
Thanks for any advice on this.
I probably spotted the issue
I dont think you can initiate a date like this ! to call a function you need have a merge notation {! } , and your code is missing that one and the variable LastMonth is storing the whole thing as string.
Addtionally you cannot init a date in a VF page like this, even if you correct the syntax, you wil get an error
All Answers
Comparision between two dates as shown bellow Saves without any compilation issues & works fine
<apex:page standardController="account">
<apex:outputText rendered="{!if((account.LastModifiedDate = account.CreatedDate), true, false)}">This is what I wanted</apex:outputText> <br/>
Some other Text!
</apex:page>
One way of doing it in your case is, instead of declaring the Apex variable in Page move it to Controller. Also, make sure to the variable as Date or Datetime depending upon the field typr you are going to comapre it with. That should work.
global with sharing class TestController {
public TestController(ApexPages.StandardController controller) {
}
public Datetime testDate{ get; set; }
public TestController(){
testDate = Date.valueof('1990-01-01');
}
}
<apex:page standardController="account" extensions="TestController">
<apex:variable var="LastMonth" value="{Date.valueOf('1990-01-01')}" />
<apex:outputText rendered="{!if((testDate = account.CreatedDate), true, false)}">This is what I wanted</apex:outputText><br/>
Plain Text!
</apex:page>
I probably spotted the issue
I dont think you can initiate a date like this ! to call a function you need have a merge notation {! } , and your code is missing that one and the variable LastMonth is storing the whole thing as string.
Addtionally you cannot init a date in a VF page like this, even if you correct the syntax, you wil get an error