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
Rabbani sayyed 8Rabbani sayyed 8 

Hi all, I need a validation rule where field can allow only primary numbers? is it possible with trigger ? if yes any sample code for this? or is this possible with config only? if yes any idea

Hi all, I need a validation rule where field can allow only primary numbers? is it possible with trigger ? if yes any sample code for this? or is this possible with config only? if yes any idea
Deepak Pandey 13Deepak Pandey 13
public class PrimeNumbers {
    public void prime(){
    for(integer i=1;i<=100;i++)
    {
        integer count=0;
        for(integer j=i; j>=1;j--)
        {
            
            if(math.mod(i,j)==0 )
            {
                count++;
            }
        }
        if(count==2 || count==1){
            
                         system.debug(i);
                   
                }                     
                 
            else{
               //system.debug('not prime');      
                }
    }
  }