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
RDN_LHRRDN_LHR 

Controller List object query

public class emailController { List<EmailMessage> emails = [select id,ParentId, Parent.Owner.Name,Parent.IsClosed, Parent.ClosedDate,status,fromaddress,toaddress,messagedate,subject from emailMessage where status ='0'

and (Parent.IsClosed = false or emailMessage.CreatedDate > Parent.ClosedDate) order by Parent.IsClosed asc, messagedate desc ]; public List<EmailMessage> getEmails() { return emails; } }

 

The above class works nicely without the red addition, but when I add this additional part I get an error "unexpected token: 'Parent.ClosedDate".

 

What is wrong with comparing one date to another date?  If I compare either date to something like "LAST_WEEK" then the query will work, but not to each other.

 

How can I accomplish comparing these dates against each other in the WHERE clause just like I would in regular SQL?

 

Much appreciated!

wesnoltewesnolte

Hey

 

The syntax is a bit off. Try putting : before Parent.ClosedDate i.e.

 

 

and (Parent.IsClosed = false or emailMessage.CreatedDate > Parent.ClosedDate)

 

 becomes

 

 

and (Parent.IsClosed = false or emailMessage.CreatedDate > :Parent.ClosedDate)

 

Cheers,

Wes 

 

 

 

RDN_LHRRDN_LHR
Putting ":" in there doesn't work because "Parent" isn't a variable.  "Parent" is the SOQL relationship name for Case.
Message Edited by RDN_LHR on 06-10-2009 07:04 AM
GuyClairboisGuyClairbois

Hi RDN_LHR,

 

did you resolve this issue? I'm struggling with the same..

 

Thanks,

Guy

GuyClairboisGuyClairbois
OK I worked around this by creating a formula field on the child object that compares the 2 dates for me. After that you can just query the formula field.