I having a custom object C1 with fields like name,email and mobile number.On an visualforce page I will enter the values and save the data.

This part is fine with me. But my requirement is when the user enters email address if it already exists then data in the <apex:inputField value={!C1__c.Email__c}"> should be replaced with asterisks indicating that the email address already exists before the user hits the save button.

The mobile number field also should follow the same pattern.

  • 1
    If the fields are of type email and phone the you will not be able to store them as ****. As for anything else, you are going to have to expand a bit as the HOW will depend completely on the WHAT you are trying to implement (VF, APEX, PB, WFR, etc.) Details including code will be needed – Eric May 15 '17 at 3:17
  • @eric, I have a email field in visualforce page. assuming the name is jose@gmail.com, when the user enters jos it will automatically display the email address in the <apex:inputfield value="{!email}" provided this email already exists. could u pls highlight on this? regarding the rest I will get back later – Pooja Biswas May 15 '17 at 4:24

Here when the user is providing a mail address, onKeyUp we are checking in the java script whether the text (size ==3) is contained in any of the contact`s mail address or not. If it is then we are overriding with "****".

Here at first we are creating a session [sforce.connection.sessionId = '{!$Api.Session_ID}';] and via this session we are doing the query . The quryVar is storing our dynamic query which is made via sforce.connection.query().

If we are getting the math then only we are overriding else we are returning the only text entered by the user as a mail address.

<apex:page controller="EmailExistController">
    <apex:includeScript value="{!URLFOR($Resource.jqueryui19, '/JQueryUI/js/jquery-1.7.1.min.js')}"/>
    <script src="/soap/ajax/39.0/apex.js"></script>
    <script src="/soap/ajax/39.0/connection.js"></script>

        function chkMail(MailAddr) {
            x2 = MailAddr.length;
            if(x2 == 3){
                var quryVar = 'SELECT Email,Id from Contact WHERE Email LIKE '+ '\'' + MailAddr +'%\' LIMIT 1';//Forming the query
                sforce.connection.sessionId = '{!$Api.Session_ID}';//This is returning a session id.
                var qr = sforce.connection.query(quryVar);
                var records = qr.getArray("records");
            if(records.length > 0 && x2 == 3){
                MailAddr = '****';
            return MailAddr; 

    <apex:form >
        <apex:outputText >Check Mail: </apex:outputText>
        <apex:inputText id="MyEmailId" value="{!mailAddEntered}" onkeyup="this.value=chkMail(this.value)"/>
  • I didnt understand. what is x2==3 , also what is {!mailEnetered}, also how to debug and chk for email value.cud u pls elaborate – Pooja Biswas May 16 '17 at 3:23
  • As you have asked for after entering 3 characters your functionality should replace the content into **** (if an existing match found), so I have checked here x2==3 .Here x2 is the current length of the text being entered. For each enter it will not work , it will work only when the user has entered 3 characters from his/her end . PS: You can modify the count based on your requirement , i.e. when you want to do the check , after how many character input you want to replace if match found. – Partha Sarathi Mandal May 16 '17 at 7:17
  • "mailAddEntered" is the controller get-set variable (public String mailAddEntered{get;set;} ) which is holding the value of the mail address entered. – Partha Sarathi Mandal May 16 '17 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.