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

Problem with subquery.
Hi,
I am writing the apex logic to get the recent account modified.
So I came up with this query :
List<Account> accList = [Select name,lastmodifieddate from Account where lastmodifieddate = :datetime.valueOf([select max(createddate) from account][0].get('expr0') + '')];
System.debug('--------------------------------------------------------- >>> ' + accList);
Can anyone tell me why is this not working ? :(
Howeven if I use '<' in place of '=' it works and lists down all the records.
Please help me to run this code.
Thanks in advance.
Anand Agrawal.
Don't you think this is wrong, as you are fetching the accounts where lastmodifieddate id equal to the lates created date. Please not value will be returned with date and time like this : 2011-06-17 00:00:00
So if the last modifieddate is 2011-06-17 00:00:01 then it won't come in result. Are you sure you want to use "select max(createddate) from account][0]" and not "select max(lastmodifieddate) from account][0]" ?
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Hey Ankit,
I m sorry for sending the wrong data. Actually I was trying the different P&C.
But still, if I make the correction it doesn't work .
List<Account> accList = [Select name,lastmodifieddate from Account where lastmodifieddate = :datetime.valueOf([select max(lastmodifieddate) from account][0].get('expr0') + '')];
System.debug('--------------------------------------------------------- >>> ' + accList);
Thanks,
Anand Agrawal.
Don't know what's your actual requirement but lat me know if it works for you.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
No, Even the code u sent is returning the same result. which is no record.
I want the details of account which is been recently modified.
But ur code returns me no record.
--Anand.
I tried your query It did not give me any result when I used it. But when i changed it to
List<Account> accList = [Select name,lastmodifieddate from Account where lastmodifieddate <: datetime.valueOf([select max(createddate) from account][0].get('expr0')+'') limit 5];
it returned me result. My past observation with dataTime query has been the same that it di not give me results for =: operator but gives me for <: or >: operators.
This is strange, code in my last reply works for me. May be there is any data issue at your end. Try running each query seperately in system logs, to track the process.
Thanks
Ankit Arora
Blog | Facebook | Blog Page
Hi Anand,
I am not sure why you are using that much complicated query. If you want to fetch latest Account record modified you can just use following query:
Hi Sonali.. I knew that way but I wanted to use the subquery.. so stuck on the pasted code... and was curious to know.. y is this not working..
Thanks,
Anand Agrawal.
I tried in this way and it works for me.
Thanks,
Sonali
Yes !! Works for me too. Don't know why this code is not helping the code creator.
Thanks
Ankit Arora
Blog | Facebook | Blog Page