+ Start a Discussion

Records dispaly in in randomly in vf page if page refresh

HI All, 


 I have 20 records in My  custom object , I need to diplay  records random , no t sam e in order if  I refresh the page How can i solve  this solution





Here is some suggestion:

  1. Get List of ID of all 68 questions.
  2. Create a Set type of variable to hold the selected questions
  3. Get the Count of elements in Step 1.
  4. In For loop for 20 counts, generate random numbner between 1 and 68 and check whether we already added the random question ? If yes then try random number again or else question in new List.
  5. Now, after for loop you will have list of all 20 questions which will be deifferent and random every time the code is executed

Integer rand = Math.floor(Math.random() *6).intValue();

list<Account> a=new list<Account>();
a = [SELECT Name FROM Account limit 5 OFFSET :rand];

chowdary marellachowdary marella

How can we store the result ?how can we differentiate which is right and wrong?