You need to sign in to do that
Don't have an account?
BigP
Can someone explain these lines of code?
Integer count = [SELECT COUNT() FROM Contact];
Integer rand = Math.floor(Math.random() * count).intValue();
Contact c = [SELECT Name FROM Contact LIMIT 10 OFFSET :rand];
Integer rand = Math.floor(Math.random() * count).intValue();
Contact c = [SELECT Name FROM Contact LIMIT 10 OFFSET :rand];
Please find the explanation for the code.
Math.random() function will generate the random number greater than 0 and less than 1
Math.floor() function will Returns the largest (closest to positive infinity) Decimal that is not greater than the argument and is equal to a mathematical integer.
intValue() is used to calculate the integer value of the decimal.
OFFSET is used to skip those many values.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,