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
gbu.varungbu.varun 

Order by Created Date is working in sandbox but not in Production

 

I am facing a sorting problem. I am using order by CreatedDate command which is working in sandbox but not in Production. 

 

Code :

List <Lead> ld1 =[Select id,Name from lead where id IN:ld order by createddate desc limit 2000 ];
    
public Lead[] getNumbers() {
	try {
		Lead[] numbers = [select Name  from Lead where id IN:ld1 order by createdDate asc limit :list_size  offset :counter];
		return numbers; 
	} 
	catch (QueryException e){
		ApexPages.addMessages(e);
		return null;
	}
}

 

Best Answer chosen by Admin (Salesforce Developers) 
gbu.varungbu.varun

I find out the issue. Standard Controller was returning only 20 records at a time. So I was getting wrong result.

All Answers

Bhawani SharmaBhawani Sharma
It shouldn't happen. Order b y clause works perfectly. Can you debug your first query result in order to check what you are getting. Also debug your offset query also.
gbu.varungbu.varun

I find out the issue. Standard Controller was returning only 20 records at a time. So I was getting wrong result.

This was selected as the best answer