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
john dsouzajohn dsouza 

remove asterisk from mobile number field

Hi
I having a custom objectProfile which has got mobile number field , Datatype=phone

Two things happen when the page loads
a) I append an ID to the URL so I will fetch all values into the respective controls
b) If mobile phone exists then it should be masked , for ex: *************

If mobile number is changed then it stores mobile number sobject field correctly without asterisk.
But if mobile number is not changed then it stores asterisk in sobject field .

any help will be rewarded.
Here is my code:
public class PrefCenterCTRL {

    
    public String fanMobile { get; set; } //masked value

     public PrefCenterCTRL()
    {
        encryptedfanID=ApexPages.currentpage().getparameters().get('id');
               
        if(String.isBlank(encryptedfanID))
        {
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Id.');
                ApexPages.addMessage(myMsg);
                return;
        }
        else
        {
          try
          {
            fetchfanvalues();
          }
          catch(System.QueryException ex){
                
              Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, 'No Record'));
          }
          
        }
        
      }
        
    public void fetchfanvalues()
    {
         fan = new fan__c();
         
         fan=[SELECT id, Mobile_Phone__c,
              FROM fan__c WHERE Encrypted_ID__c=:encryptedfanID];
            
       if(!string.isBlank(fan.Mobile_Phone__c))
       {
            fan_Mobile=fan.Mobile_Phone__c;
            fanMobile=maskPhone(fan.Mobile_Phone__c);
       }      
      }}

//save the values
  public void SaveValues()
    {
            
      if (fan != NULL)
      {
              
         
      if (fanMobile.equals(maskPhone(fanMobile)))
      {
          fan.Mobile_Phone__c=fan_Mobile;
      }
      else
      {
      
       fan.Mobile_Phone__c=string.valueOf(fanMobile);
      
      }

public PageReference btn_profile_saveChanges()
    {
        SaveValues();
        return null;
    }
  }
<apex:page controller="PrefCenterCTRL" docType="html-5.0">
<apex:form>

           <apex:inputText value="{!fanMobile}" styleClass="form-control"/>

<apex:commandButton value="Save"  action="{!btn_profile_saveChanges}/>
<apex:form>
</apex:page>

Thanks
JohnD
 
AvaneeshAvaneesh
Hi John ,
How you know that your Contact values are changed
john dsouzajohn dsouza
Hi
Initially when page loads, mobilephone value is masked. so in controller's constructor I am capturing the original value(I mean unmasked value) into fan_Mobile which is then passed to sobject.mobile_phone__c assuming the user doesnt make changes and hits save button.

thanks
John D
 
john dsouzajohn dsouza
Hi
Now if the user changes the mobile number then the changed value shud be reflected in sobject but it is not happening

thanks
JohnD
AvaneeshAvaneesh
Hi John,

I sloved your problem in my org but i used Account object in my vf page Run the code and and Let me know if this is helpful 
Marked as best answer if this was helpful
Thank you
Avaneesh Singh
public class AccountWithPhoneValue {

public String phone{get;set;}
public String acc_Name{get;set;}
Public String Old_phone{get;set;}
Public Id CurrentID{get;set;}
    public AccountWithPhoneValue()
    {
       List<Account> acc=[select id,name,phone from Account where phone !=NULL Limit 1];       
          for(Account ac:acc)
          {
              phone=ac.Phone;
              acc_name=ac.name;
              old_phone=ac.phone;  
              CurrentId=ac.id;       
                     
          }      
    }
     public PageReference Save() {
     System.debug('@@@@@@@@@@@@@@@@'+phone);
             if(old_phone.equals(phone))// contact no is not change then it store astrick in sobject field 
             {
                 phone=phone.replaceAll('.', '*'); // a regex to change String into Astrick 
                 Account accnew = new Account();
                 accnew.id=CurrentId;
                 accnew.phone=phone;
                 update accnew;
             }else
             {
                 Account accnew = new Account();
                 accnew.id=CurrentId;
                 accnew.phone=phone;
                 update accnew;
             }
        return null;
    }
}
 
<apex:page controller="AccountWithPhoneValue" sidebar="false">
    <apex:form >
        <apex:pageblock >
            <apex:pageblockSection >
                <apex:outputText value="{!acc_Name}"></apex:outputText>
                <apex:inputtext value="{!phone}"/>
            </apex:pageblockSection>
            <apex:pageBlockButtons >
                <apex:commandButton value="save" action="{!Save}"/>
            </apex:pageBlockButtons>
        </apex:pageblock>
    </apex:form>
</apex:page>


AvaneeshAvaneesh
Hi john ,

if your problem is sloved then mark as best answer else Let me know the issue ??

Thank you 
Avaneesh Singh
john dsouzajohn dsouza
Hi avneesh
In my custom object email is an required field, so update throws error.

any other way wherein I can use inputhidden field in vf page and capture that value in controller?

thanks
JohnD
AvaneeshAvaneesh
Hi John ,

Send me your code and mark that line where it throw error ...Let me check once

Thank you 
Avaneesh Singh