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
Justin DJustin D 

Minimum number (3) of characters does not seem to work

I am trying to have a minimum 3 characters of First Name and Last Name in order to retrieve the data, but now, it retrieves result of data even it is less than 3 characters.

Thanks in advance.

Bottom is Apex code:
public with sharing class psw {
    public String sfprn { get; set; }
    public String mrn {get;set;}
    public String lname {get;set;}
    public String fname {get;set;}

public class TableRow2{
    public String sfprn {get;set;}
    public String mrn {get;set;}
    public String lname {get;set;}
    public String fname {get;set;}
    public Decimal SurveySelection {get;set;}

public List<TableRow2> RowList {get; set;}

public PageReference searchPatients(){

    RowList = new List<TableRow2>();
    TableRow2 tr;

    String bind_fname = string.isBlank(fName) ? null : (fname.left(3) + '%');
    String bind_lname = string.isBlank(lname) ? null : (lname.left(3) + '%');

    for(Patient__c con : [SELECT sfprn__c, 
                                (select SurveySelection__c.SurveySelection__c from SurveySelections__r) 
                                FROM Patient__c
                                where ( mrn__c =:mrn )
                              //or ( LName__c =:lname and FName__c =:fname) LIMIT 1 
                                or ( LName__c LIKE :bind_lname and FName__c LIKE :bind_fname ) LIMIT 1                       
        tr = new TableRow2();
        tr.sfprn = con.sfprn__c;
        tr.mrn = con.mrn__c;
        tr.lname = con.LName__c;
        tr.fname = con.FName__c;
        tr.SurveySelection = con.SurveySelections__r.isEmpty() ? null : con.SurveySelections__r[0].SurveySelection__c;


     return null;   


Bottom is VF code:

<apex:page Controller="psw" showHeader="false" sidebar="false">
<apex:form >
<apex:pageBlock >
    <!-- Search button-->
    <apex:pageBlockButtons location="top">
        <apex:commandButton value="Search" action="{!searchPatients}" reRender="contact-table"/>

    <apex:pageBlockSection id="contact-table" columns="1">
        <!-- Input starts -->
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="MRN" />
            <apex:inputText value="{!mrn}"/>            

        <apex:pageBlockSectionItem >
            <apex:outputLabel value="Last Name" />
            <apex:inputText value="{!lname}"/>            
        <apex:pageBlockSectionItem >
            <apex:outputLabel value="First Name" />
            <apex:inputText value="{!fname}"/>            
        <!-- Input ends -->

        <!-- Output 1 starts --->
        <apex:pageBlockTable value="{!RowList}" var="c">
            <apex:column >
                <apex:facet name="header">MRN</apex:facet>
            <apex:column >
                <apex:facet name="header">Last Name</apex:facet>
            <apex:column >
                <apex:facet name="header">First Name</apex:facet>
         <!-- Output 1 ends --->  
Lokesh KumarLokesh Kumar
HI Justin,
You can put a condition before your logic by calculating the length of fname if (fname.length() > 3) then enter else null.

Justin DJustin D
Hi Lokesh, How do I express "enter"?