• john dsouza
  • NEWBIE
  • 25 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 16
    Replies
I have a picklist defined in vf page and I have created a custom setting (Countries__c ) which has a field CountryCode__c .
so its like this
Australia  CA
India        IN
America   USA

when the visual force page loads I want the picklist values to be sorted but it is not happening.
public class someclass
{
private List<SelectOption> countryCodeList = new List<SelectOption>();


    //Holds the Country Code for the selected option

    public String selectedCountryCode {get; set;}

   }

public  List<SelectOption> getCountryCodes() 
   {
        if(countryCodeList.isEmpty())
        {
           
          for(Countries__c country :Countries__c.getAll().values())
          {

            countryCodeList.add(new SelectOption(country.CountryCode__c, country.Name));
          }

        }

        countryCodeList.sort();  //doesnt work
        return countryCodeList;
   }
Please help me out.

Thanks
John
 
I have two custom objects fan and preferences.
IN fan object I have email,birthdate field and in preference sobject I have a multi select picklist wihich has a default value as ''ALTERNATIVE / INDIE'.

Preference object has a lookup to Fan object.

The email field(mandatory) is masked with asterisk, so when the page loads the code masks the contents and when the user clicks save button page is refreshed and email field value is masked.

Also when the page loads I  append an ID to the url to fetch the values.
Here is a piece of code .
public class PrefCenterCtrl{
      
    public String fanDOB { get; set; }
    public String fanCountry_Region { get; set; }
    public String fanEmail { get; set; } 
    public String fan_email{get;set;}  

     public String encryptedfanID{get;set;}
    
    public String mid{get;set;}
    
    public fan__c fan{get;set;}
      
    public Preference__c pref;
    public boolean Genre_Alternative_Indie { set; get; }

    private List<SelectOption> countryCodeList = new List<SelectOption>();

     public PrefCenterCTRL()
    {
        encryptedfanID='';
        mid='';
        
        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, Email__c,Birthdate__c,Country_Region__c
              FROM fan__c 
              WHERE Encrypted_ID__c=:encryptedfanID];
         
         if (fan != NULL)
         {
                        
             fan_email=fan.Email__c;
             
             if(fan_email != null && fan_email != '' )
             {
                fanEmail=maskEmail(fan_email);
             }
             else
             {
                 fan_Email = fan.Email__c;
             }}

          pref=new Preference__c();
        
       try
       {
        pref = [SELECT Preferred_Genre__c
                      FROM Preference__c
                      WHERE Fan_Id__c = :fan.Id];
    //Preferred_Genre__c is defined as Multiselect Picklist in Preference object   
    String Pref_Genre = pref.Preferred_Genre__c;  
       
       if(Pref_Genre != null)
       {
             string[] Genres = pref_Genre.split(';');
                    
             for(integer G=0; G<=Genres.size()-1; G++)
             {
                            
                            if(Genres[G] == 'ALTERNATIVE / INDIE')
                                Genre_Alternative_Indie = true;
            }

        }               
           
        catch(system.Exception ex)
        {
          
        }
     }

//code to mask the email with asterisk when the page loads and also when the user clicks save button the email field content is masked with asterisk
  private String maskEmail(String sEmail)
    {   String sMaskedEmail;      
        String[] aEmail = sEmail.split('@');   
        if(aEmail.size() == 2)
        {      
          sMaskedEmail = aEmail[0].left(1); 
          for(integer i=0; i < aEmail[0].length() - 1; i++)
          {
            sMaskedEmail += '*';
          }      
          String[] aEmail2 = aEmail[1].split('\\.', 2); 
          sMaskedEmail += '@' + aEmail2[0].left(1);  
          for(integer i=0; i < aEmail2[0].length() - 1; i++)
          { 
            sMaskedEmail += '*';
          }   
          sMaskedEmail += '.' + aEmail2[1];  
        } 
          return sMaskedEmail; 
    }

//The country along with its codes is stored in custom setting
  public  List<SelectOption> getCountryCodes() 
   {
        if(countryCodeList.isEmpty())
        {
           
          for(Countries__c country :Countries__c.getAll().values())
          {

            countryCodeList.add(new SelectOption(country.CountryCode__c, country.Name));
          }

        }

        countryCodeList.sort();
        return countryCodeList;
   }

public void LoadMaskedValues()
   {
       fan = new fan__c();
       
       if (fan != NULL)
       {
      
           fan=[SELECT id, Email__c,Mobile_Phone__c
                       FROM fan__c 
                       WHERE Encrypted_ID__c=:encryptedfanID];
                       
           if(!string.isBlank(fan.Email__c))
           {
                fan_email=fan.Email__c;
                fanEmail=maskEmail(fan.Email__c);
           }
}
 
 public void SaveValues()
 {
     if (fan != NULL)
      {
      
      if(!fanEmail.contains('*'))
      {     
            integer count = [SELECT Count() FROM Fan__c WHERE Email__c =:fanEmail];
            if(count > 0)
            {
                Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, 'This Fan Already Exists In The System'));
                return;
            }
             else if(string.isEmpty(fanEmail))
            {
               ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Email Cannot Be Blank')); 
               return;
            
            }
            else if(!Pattern.matches('([a-zA-Z0-9_\\-\\.]+)@((\\[a-z]{1,3}\\.[a-z]{1,3}\\.[a-z]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})', fanEmail))
            {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Invalid Email')); 
              return;
            }
            else
            {
              fan.Email__c = fanEmail;
            }
       }
      if(!string.isBlank(fanDOB))
      {
       fan.Birthdate__c=Date.parse(fanDOB); 
      }

   try
      {
         upsert fan;
      }
      catch(System.DmlException ex)
      {
            
        Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, 'Cannot Update the Record.'+ex.getMessage()));
      }
     }   
     
     LoadMaskedValues();         
}    

public void SavePreferences()
    {    
    
    if (pref != NULL)
    {
        string Preferred_Genre = '';
        
        if(Genre_Alternative_Indie == true){
            
            Preferred_Genre += 'ALTERNATIVE / INDIE ;';
        }      

       try{
            
                pref.Preferred_Genre__c = Preferred_Genre;
                pref.fan_id__c = fan.Id;
                
                upsert pref;
                    
        }catch(System.DMLException ex){
            
            Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, ex.getMessage()));
        }
      }}

 public PageReference btn_profile_saveChanges()
    {
        SaveValues();
        return null;
    }
    
    
    public void btn_preferences_saveChanges()
    {
      SavePreferences();    
    }

Please help me in writing a test class with 100% code coverage.

Thanks
John
Hello

I have created a new custom setting say Countries (api name : Countries__c) and has field CountryCode__c
this means
 Australia AU
 India IN
 Kenya  KN

I have the visualforce page as follows.
<apex:selectList value="{!fanCountry_Region}" size="1">
   <apex:selectOption itemValue="None" itemLabel="--Select--"></apex:selectOption> <
     apex:selectOption itemValue="United Kingdom" itemLabel="United Kingdom">
  </apex:selectOption> <apex:selectOption itemValue="India" itemLabel="Germany">
</apex:selectOption>
</apex:selectList>

I need to remove the above values and need to fetch the values from the custom setting .

So please let me know what changes should I make to visualforce page and how to fetch values in controller for picklist.

assume , I select Australia from picklist in visualforc page then it gets saved to sobject.

any help will be grealty appreciated

Thanks
John D
Hello
I have two custom objects , fan__c    and   subscription__c

Fan object has fields (ID, email__c)

subscription object has fields(ID,fan_ID__c,mailing_list_name)

subscription object has a lookup to fan object as  : Fan_ID__cLookup(Fan)

pls help in framing the subscription query from child to parent where child is subscription object and parent is fan object.

I want to frame a query on subscription object that will fetch the related email of fan object

pls help me out
thanks
JohnD
 
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
 
Hello
I have a visual force page purely designed using HTML5.
I have a inputText field called email stored inside a custom object preferences.

If the value in the inputText field changes then I want to capture the changed value into my apex controller for further processing.

Here is what I am trying to achieve.
public class mycontroller {

 public String fanEmail{get;set;}
}

<apex:page controller="mycontroller docType="html-5.0">
<body>
<div class="form-group label-floating">
 <apex:form
  <label class="control-label">EMAIL *</label>
   <apex:inputText value="{!Email}" id="memail" 
                              onchange="doSearch()';" 
                             styleClass="form-control"/>
           </div>
 <apex:commandButton value="SAVE CHANGES" action="{!btn_profile_saveChanges}" styleClass="btn btn-success"/>

</apex:form>
</apex:page>
I know that we can use onchange event of <apex:inputText> to achieve this and create a javascript but not sure how to proceed further.

any help will be rewarded.

Thanks
JohnD
 
Hello 
I have a custom object fan which has three fields, email , firstname and lastname , email field being mandatory.
first time when page  loads, I append an ID known as encryptedfanID to the browser URL , thereby it loads the respective values into the fields.
so this part is working fine
suppose if I do not append any ID to the URL and hit the save button without entering any valies then it throws error " ateempt to deference a null object" error.

a piece of code explaining the above is provided.
public class PrefCenterCTRL{

    //Profile Tab 
     public String fanLastName { get; set; }
    public String fanFirstName { get; set; }
    public String fanEmail { get; set; }    
    public String encryptedfanID{get;set;}
    public fan__c fan{get;set;}
   
public PrefCenterCTRL()
    {
     try
     {
        encryptedfanID=ApexPages.currentpage().getparameters().get('id');
        system.debug('@@@'+encryptedfanID);
        
        if(String.isBlank(ApexPages.currentPage().getParameters().get('id')))
        {
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Id.');
                ApexPages.addMessage(myMsg);
                return;
        }
        else
        {
          
          fetchfanvalues();
        }
        
      }
      catch(Exception e){
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage());
            ApexPages.addMessage(myMsg);
            return;
      }   
    }

 public void fetchfanvalues()
    {
    try
    {
       fan=[SELECT id, Email__c,First_Name__c,Last_Name__c,
            FROM fan__c 
           WHERE Encrypted_ID__c=:encryptedfanID];
            
      
       if(!string.isBlank(fan.Email__c))
       {
            fan_email=fan.Email__c;
       }

       if(!string.isBlank(fan.First_Name__c))
       {
           fanFirstName=fan.First_Name__c;
       }
       
       if(!string.isBlank(fan.Last_Name__c))
       {
           fanLastName=fan.Last_Name__c;
       }
  }

 public void SaveValues()
    {
               
      if(!string.isBlank(fan_email))
      {
       fan.Email__c=fan_email;
      }
      
      if(!string.isBlank(fanMobile))
      {
        fan.Mobile_Phone__c=fanMobile;
      }
      
      if(!string.isBlank(fanFirstName))
      {
         fan.First_Name__c=fanFirstName;
    }
    public PageReference btn_profile_saveChanges()
    {
        SaveValues();
        return null;
    }
}

<apex:page controller="PrefCenterCTRL" 
           docType="html-5.0" 
           showHeader="false" >

<apex:form>

         <apex:inputText value="{!fanEmail}" id="email_val"/>     
         <apex:inputText value="{!fanfirstname}" id="firstname"/>  
         <apex:inputText value="{!fanLastName}" id="lastname"/> 
<apex:commandButton value="SAVE CHANGES"
                    action="{!btn_profile_saveChanges}" />
<apex:form>
</apex:page>
I hope I am pretty clear, I request the forum membets to kndly help me out.

thanks
JohnD
 
I have a picklist defined in vf page and I have created a custom setting (Countries__c ) which has a field CountryCode__c .
so its like this
Australia  CA
India        IN
America   USA

when the visual force page loads I want the picklist values to be sorted but it is not happening.
public class someclass
{
private List<SelectOption> countryCodeList = new List<SelectOption>();


    //Holds the Country Code for the selected option

    public String selectedCountryCode {get; set;}

   }

public  List<SelectOption> getCountryCodes() 
   {
        if(countryCodeList.isEmpty())
        {
           
          for(Countries__c country :Countries__c.getAll().values())
          {

            countryCodeList.add(new SelectOption(country.CountryCode__c, country.Name));
          }

        }

        countryCodeList.sort();  //doesnt work
        return countryCodeList;
   }
Please help me out.

Thanks
John
 
I have two custom objects fan and preferences.
IN fan object I have email,birthdate field and in preference sobject I have a multi select picklist wihich has a default value as ''ALTERNATIVE / INDIE'.

Preference object has a lookup to Fan object.

The email field(mandatory) is masked with asterisk, so when the page loads the code masks the contents and when the user clicks save button page is refreshed and email field value is masked.

Also when the page loads I  append an ID to the url to fetch the values.
Here is a piece of code .
public class PrefCenterCtrl{
      
    public String fanDOB { get; set; }
    public String fanCountry_Region { get; set; }
    public String fanEmail { get; set; } 
    public String fan_email{get;set;}  

     public String encryptedfanID{get;set;}
    
    public String mid{get;set;}
    
    public fan__c fan{get;set;}
      
    public Preference__c pref;
    public boolean Genre_Alternative_Indie { set; get; }

    private List<SelectOption> countryCodeList = new List<SelectOption>();

     public PrefCenterCTRL()
    {
        encryptedfanID='';
        mid='';
        
        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, Email__c,Birthdate__c,Country_Region__c
              FROM fan__c 
              WHERE Encrypted_ID__c=:encryptedfanID];
         
         if (fan != NULL)
         {
                        
             fan_email=fan.Email__c;
             
             if(fan_email != null && fan_email != '' )
             {
                fanEmail=maskEmail(fan_email);
             }
             else
             {
                 fan_Email = fan.Email__c;
             }}

          pref=new Preference__c();
        
       try
       {
        pref = [SELECT Preferred_Genre__c
                      FROM Preference__c
                      WHERE Fan_Id__c = :fan.Id];
    //Preferred_Genre__c is defined as Multiselect Picklist in Preference object   
    String Pref_Genre = pref.Preferred_Genre__c;  
       
       if(Pref_Genre != null)
       {
             string[] Genres = pref_Genre.split(';');
                    
             for(integer G=0; G<=Genres.size()-1; G++)
             {
                            
                            if(Genres[G] == 'ALTERNATIVE / INDIE')
                                Genre_Alternative_Indie = true;
            }

        }               
           
        catch(system.Exception ex)
        {
          
        }
     }

//code to mask the email with asterisk when the page loads and also when the user clicks save button the email field content is masked with asterisk
  private String maskEmail(String sEmail)
    {   String sMaskedEmail;      
        String[] aEmail = sEmail.split('@');   
        if(aEmail.size() == 2)
        {      
          sMaskedEmail = aEmail[0].left(1); 
          for(integer i=0; i < aEmail[0].length() - 1; i++)
          {
            sMaskedEmail += '*';
          }      
          String[] aEmail2 = aEmail[1].split('\\.', 2); 
          sMaskedEmail += '@' + aEmail2[0].left(1);  
          for(integer i=0; i < aEmail2[0].length() - 1; i++)
          { 
            sMaskedEmail += '*';
          }   
          sMaskedEmail += '.' + aEmail2[1];  
        } 
          return sMaskedEmail; 
    }

//The country along with its codes is stored in custom setting
  public  List<SelectOption> getCountryCodes() 
   {
        if(countryCodeList.isEmpty())
        {
           
          for(Countries__c country :Countries__c.getAll().values())
          {

            countryCodeList.add(new SelectOption(country.CountryCode__c, country.Name));
          }

        }

        countryCodeList.sort();
        return countryCodeList;
   }

public void LoadMaskedValues()
   {
       fan = new fan__c();
       
       if (fan != NULL)
       {
      
           fan=[SELECT id, Email__c,Mobile_Phone__c
                       FROM fan__c 
                       WHERE Encrypted_ID__c=:encryptedfanID];
                       
           if(!string.isBlank(fan.Email__c))
           {
                fan_email=fan.Email__c;
                fanEmail=maskEmail(fan.Email__c);
           }
}
 
 public void SaveValues()
 {
     if (fan != NULL)
      {
      
      if(!fanEmail.contains('*'))
      {     
            integer count = [SELECT Count() FROM Fan__c WHERE Email__c =:fanEmail];
            if(count > 0)
            {
                Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, 'This Fan Already Exists In The System'));
                return;
            }
             else if(string.isEmpty(fanEmail))
            {
               ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Email Cannot Be Blank')); 
               return;
            
            }
            else if(!Pattern.matches('([a-zA-Z0-9_\\-\\.]+)@((\\[a-z]{1,3}\\.[a-z]{1,3}\\.[a-z]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})', fanEmail))
            {
              ApexPages.addmessage(new ApexPages.message(ApexPages.severity.Error, 'Invalid Email')); 
              return;
            }
            else
            {
              fan.Email__c = fanEmail;
            }
       }
      if(!string.isBlank(fanDOB))
      {
       fan.Birthdate__c=Date.parse(fanDOB); 
      }

   try
      {
         upsert fan;
      }
      catch(System.DmlException ex)
      {
            
        Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, 'Cannot Update the Record.'+ex.getMessage()));
      }
     }   
     
     LoadMaskedValues();         
}    

public void SavePreferences()
    {    
    
    if (pref != NULL)
    {
        string Preferred_Genre = '';
        
        if(Genre_Alternative_Indie == true){
            
            Preferred_Genre += 'ALTERNATIVE / INDIE ;';
        }      

       try{
            
                pref.Preferred_Genre__c = Preferred_Genre;
                pref.fan_id__c = fan.Id;
                
                upsert pref;
                    
        }catch(System.DMLException ex){
            
            Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, ex.getMessage()));
        }
      }}

 public PageReference btn_profile_saveChanges()
    {
        SaveValues();
        return null;
    }
    
    
    public void btn_preferences_saveChanges()
    {
      SavePreferences();    
    }

Please help me in writing a test class with 100% code coverage.

Thanks
John
Hello

I have created a new custom setting say Countries (api name : Countries__c) and has field CountryCode__c
this means
 Australia AU
 India IN
 Kenya  KN

I have the visualforce page as follows.
<apex:selectList value="{!fanCountry_Region}" size="1">
   <apex:selectOption itemValue="None" itemLabel="--Select--"></apex:selectOption> <
     apex:selectOption itemValue="United Kingdom" itemLabel="United Kingdom">
  </apex:selectOption> <apex:selectOption itemValue="India" itemLabel="Germany">
</apex:selectOption>
</apex:selectList>

I need to remove the above values and need to fetch the values from the custom setting .

So please let me know what changes should I make to visualforce page and how to fetch values in controller for picklist.

assume , I select Australia from picklist in visualforc page then it gets saved to sobject.

any help will be grealty appreciated

Thanks
John D
Hello
I have two custom objects , fan__c    and   subscription__c

Fan object has fields (ID, email__c)

subscription object has fields(ID,fan_ID__c,mailing_list_name)

subscription object has a lookup to fan object as  : Fan_ID__cLookup(Fan)

pls help in framing the subscription query from child to parent where child is subscription object and parent is fan object.

I want to frame a query on subscription object that will fetch the related email of fan object

pls help me out
thanks
JohnD
 
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
 
Hello
I have a visual force page purely designed using HTML5.
I have a inputText field called email stored inside a custom object preferences.

If the value in the inputText field changes then I want to capture the changed value into my apex controller for further processing.

Here is what I am trying to achieve.
public class mycontroller {

 public String fanEmail{get;set;}
}

<apex:page controller="mycontroller docType="html-5.0">
<body>
<div class="form-group label-floating">
 <apex:form
  <label class="control-label">EMAIL *</label>
   <apex:inputText value="{!Email}" id="memail" 
                              onchange="doSearch()';" 
                             styleClass="form-control"/>
           </div>
 <apex:commandButton value="SAVE CHANGES" action="{!btn_profile_saveChanges}" styleClass="btn btn-success"/>

</apex:form>
</apex:page>
I know that we can use onchange event of <apex:inputText> to achieve this and create a javascript but not sure how to proceed further.

any help will be rewarded.

Thanks
JohnD
 
Hello 
I have a custom object fan which has three fields, email , firstname and lastname , email field being mandatory.
first time when page  loads, I append an ID known as encryptedfanID to the browser URL , thereby it loads the respective values into the fields.
so this part is working fine
suppose if I do not append any ID to the URL and hit the save button without entering any valies then it throws error " ateempt to deference a null object" error.

a piece of code explaining the above is provided.
public class PrefCenterCTRL{

    //Profile Tab 
     public String fanLastName { get; set; }
    public String fanFirstName { get; set; }
    public String fanEmail { get; set; }    
    public String encryptedfanID{get;set;}
    public fan__c fan{get;set;}
   
public PrefCenterCTRL()
    {
     try
     {
        encryptedfanID=ApexPages.currentpage().getparameters().get('id');
        system.debug('@@@'+encryptedfanID);
        
        if(String.isBlank(ApexPages.currentPage().getParameters().get('id')))
        {
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: Invalid Id.');
                ApexPages.addMessage(myMsg);
                return;
        }
        else
        {
          
          fetchfanvalues();
        }
        
      }
      catch(Exception e){
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,e.getMessage());
            ApexPages.addMessage(myMsg);
            return;
      }   
    }

 public void fetchfanvalues()
    {
    try
    {
       fan=[SELECT id, Email__c,First_Name__c,Last_Name__c,
            FROM fan__c 
           WHERE Encrypted_ID__c=:encryptedfanID];
            
      
       if(!string.isBlank(fan.Email__c))
       {
            fan_email=fan.Email__c;
       }

       if(!string.isBlank(fan.First_Name__c))
       {
           fanFirstName=fan.First_Name__c;
       }
       
       if(!string.isBlank(fan.Last_Name__c))
       {
           fanLastName=fan.Last_Name__c;
       }
  }

 public void SaveValues()
    {
               
      if(!string.isBlank(fan_email))
      {
       fan.Email__c=fan_email;
      }
      
      if(!string.isBlank(fanMobile))
      {
        fan.Mobile_Phone__c=fanMobile;
      }
      
      if(!string.isBlank(fanFirstName))
      {
         fan.First_Name__c=fanFirstName;
    }
    public PageReference btn_profile_saveChanges()
    {
        SaveValues();
        return null;
    }
}

<apex:page controller="PrefCenterCTRL" 
           docType="html-5.0" 
           showHeader="false" >

<apex:form>

         <apex:inputText value="{!fanEmail}" id="email_val"/>     
         <apex:inputText value="{!fanfirstname}" id="firstname"/>  
         <apex:inputText value="{!fanLastName}" id="lastname"/> 
<apex:commandButton value="SAVE CHANGES"
                    action="{!btn_profile_saveChanges}" />
<apex:form>
</apex:page>
I hope I am pretty clear, I request the forum membets to kndly help me out.

thanks
JohnD