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
V AnandV Anand 

How to print leads in visualforce which follows insertion order.

 

If displaying  leads in visualforce they are not following insertion order.

please anyone help me to print leads in insertion order.

 

  public list<lead> getUnas() {  

list<lead> cc=[select created_time__c,id,quemember__c,ownerid,lastname,company,status,email from lead where ownerid=\'00G90000000OTUm\' order by created_time__c];

return cc;

}

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

The autonumber is guaranteed to be increasing (although not incremental), so I'm surprised that doesn't reflect the order of insertion.  Can you tell us a bit more about how you are inserting?

All Answers

Baktash H.Baktash H.

why don't you use the standard field CreatedDate?

list<lead> cc=[select created_time__c,id,quemember__c,ownerid,lastname,company,status,email from lead where ownerid=\'00G90000000OTUm\' order by createdDate];

 

bob_buzzardbob_buzzard

Is this because there are a number of records with the same createdtime?

 

Its tempting to think that you can just order by id, e.g.

 

list<lead> cc=[select created_time__c,id,quemember__c,ownerid,lastname,company,status,email from lead where ownerid=\'00G90000000OTUm\' order by id ASC

 

but I don't think I've seen any docs guaranteeing that the ids will increment/increase with each insert, so I'm not sure whether that would work in all cases.  To guarantee ordering you may need to add an autonumber field and order by that.

 

 

 

SamuelDeRyckeSamuelDeRycke

Are you sure your date in created_time__c is what you want it to be ?  Try ordering on the CreatedDate field.

 

 

edit: well if this isn't a popular question, 3 replies in a single minute :D

Baktash H.Baktash H.

@Sdry
and one of the answers is just the repetion of an other one :P

 

 

bob_buzzardbob_buzzard

The only downside with createddate is if you inserted a number of records at once I think you'd lose the order of insertion there as they would have the same createddate value.  

Baktash H.Baktash H.

And if he wants different createddates but also insert a list he has to use a batch, right bob?

V AnandV Anand

Thank you for your valuable reply...

 

I created  autonumber field on lead and order by that auto number but still it not follows insertion order..

 

what I can do....

bob_buzzardbob_buzzard

The autonumber is guaranteed to be increasing (although not incremental), so I'm surprised that doesn't reflect the order of insertion.  Can you tell us a bit more about how you are inserting?

This was selected as the best answer
V AnandV Anand

I am inserting through web-to-lead......

 

and Its working fine thankyou for your support.