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
viswadaviswada 

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

 

JitendraJitendra

Hi,

 

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
marella1800marella1800

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

list<Account> a=new list<Account>();
a = [SELECT Name FROM Account limit 5 OFFSET :rand];
System.debug('@@@@Account@@@@@'+a);

chowdary marellachowdary marella

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