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>
<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){
//alert('present');
MailAddr = '****';
}
return MailAddr;
}
</script>
<apex:form >
<apex:outputText >Check Mail: </apex:outputText>
<apex:inputText id="MyEmailId" value="{!mailAddEntered}" onkeyup="this.value=chkMail(this.value)"/>
</apex:form>
</apex:page>