The impending Javalambre Physics of the accelerating universe Astrophysical Survey (J-PAS) will be the first wide-field survey of $gtrsim$ 8500 deg$^2$ to reach the `stage IV category. Because of the redshift resolution afforded by 54 narrow-band filters, J-PAS is particularly suitable for cluster detection in the range z$<$1. The photometric redshift dispersion is estimated to be only $sim 0.003$ with few outliers $lesssim$ 4% for galaxies brighter than $isim23$ AB, because of the sensitivity of narrow band imaging to absorption and emission lines. Here we evaluate the cluster selection function for J-PAS using N-body+semi-analytical realistic mock catalogues. We optimally detect clusters from this simulation with the Bayesian Cluster Finder, and we assess the completeness and purity of cluster detection against the mock data. The minimum halo mass threshold we find for detections of galaxy clusters and groups with both $>$80% completeness and purity is $M_h sim 5 times 10^{13}M_{odot}$ up to $zsim 0.7$. We also model the optical observable, $M^*_{rm CL}$-halo mass relation, finding a non-evolution with redshift and main scatter of $sigma_{M^*_{rm CL} | M_{rm h}}sim 0.14 ,dex$ down to a factor two lower in mass than other planned broad-band stage IV surveys, at least. For the $M_{rm h} sim 1 times 10^{14}M_{odot}$ Planck mass limit, J-PAS will arrive up to $zsim 0.85$ with a $sigma_{M^*_{rm CL} | M_{rm h}}sim 0.12 , dex$. Therefore J-PAS will provide the largest sample of clusters and groups up to $zsim 0.8$ with a mass calibration accuracy comparable to X-ray data.