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

Update random number in a SObject
I am currently working on survey to display a random questions, For that i need to update random numbers to a sobject. But System.NullPointerException: occurred in my code.
Apex:
VF:
Notes: randomizer.getRandomNumber
Apex:
public class update_random_question { public List<Question__c> scope{get;set;} public update_random_question() { for(Question__c a : scope) { a.orderby__c = randomizer.getRandomNumber(100); } update scope; } }
VF:
<apex:page controller="update_random_question"> <apex:form> <apex:commandButton Value="Begin" action="{!update_random_question}"/> </apex:form> </apex:page>
Notes: randomizer.getRandomNumber
Hi Ragul,
It seems that you need to initialize scop and provide some value to it by doing a query on Question__c.
- Why do you have the property "scope" when you are not data-binding it to VF or, in general, to any other class outside the base class. A private variable should work fine.
- You need to query (soql) and populate the instance variable of the Question__c object to have questions in it.
I hope it helps.Try using below code for your requirement.
I hope this will solve your issue.
You don't need a stored value for "order by" nor "randomizer".
Lists are ordered by default.
Just try the code below (very simple and it can be written by many other ways) Regards
Alain