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
anu_karthianu_karthi 

caling current input field value

Hi Everyone,

 

I have created a page for a custom object with all its custom fields as input fields...Now i want to fetch d current input field value in to my controller so to compare  d current   input field value  with d corresponding stored values in salesforce dbase ..iam unable to fetch the current input field value from visual force page to d

apex controller..

 

 Can some one plz provide me with an example code in fetching d input field values from d   

visualforce page to d controller....

 

                                                                                                                    Thanks & Regards,

                                                                                                                                  Anu......

S_LieS_Lie

private Object obj  {get;set;}

public AccountPlanController(ApexPages.StandardController controller) {
            this.obj = (Opportunity)controller.getRecord();

String Myname = obj.Name;


}

 

<apex:inputField value'{!obj}'/>

 

 Myname will return the input from the user.

anu_karthianu_karthi

Hi ,

 I have done as if u suggested but still iam not able to fetch d field in to controller..

 

Apexclass

public class MyClassnew11 {
private CAF_Bank__c obj  {get;set;}
private static final Boolean DISABLED = false;
private static final Boolean ENABLED = true;
public Boolean disableInput {get; set;}
 boolean isSaveButtonDisabled = false;
  boolean isNewButtonDisabled = false;
  boolean isEditButtonDisabled = false;
  boolean isDeleteButtonDisabled=false;
List<String> BankBranchList = new List<String>();
ApexPages.StandardController con;
public MyClassnew11(ApexPages.StandardController controller){
this.obj = (CAF_Bank__c)controller.getRecord();
String mybranchcode = obj.Branch_Code__c;
setButtonStatus('save', DISABLED);
setButtonStatus('edit', DISABLED);
setButtonStatus('delete',DISABLED);
this.con = controller;
CAF_Bank__c[] branches = [SELECT Branch_Code__c FROM CAF_Bank__c];
for (CAF_Bank__c b : branches) {
BankBranchList.add(b.Branch_Code__c);
}
}
public String[] getBankBranchList() {
return BankBranchList;
String theId = ApexPages.currentPage().getParameters().get('id');
Public pageReference move()
{
   PageReference newpage=page.caftest5;
   newPage.setRedirect(true);
   return newpage;
   }
 public void save() {
try
{
 con.save();
setButtonStatus('save', DISABLED);
setButtonStatus('edit', ENABLED);
setButtonStatus('new', ENABLED);
setButtonStatus('delete', ENABLED);
}
catch(Exception ex1)
{
}
}
public PageReference newRecord()
{
PageReference pr = System.Page.caftest11; // or 'new PageReference('url');//
pr.setRedirect(true);
return pr;
}
public PageReference hmpgmove()
{
PageReference pr =new PageReference('https://ap1.salesforce.com/home/home.jsp'); // or 'new PageReference('url');//

pr.setRedirect(true);
return pr;


public PageReference create()
{

enableCloseDateInput();
return move();
}
public boolean getIsSaveButtonDisabled()
{
  return isSaveButtonDisabled;
}
public boolean getIsEditButtonDisabled()
{
  return isEditButtonDisabled;
}
public boolean getIsNewButtonDisabled()
{
  return isNewButtonDisabled;
}
public boolean getIsDeleteButtonDisabled()
{
  return isDeleteButtonDisabled;
}
  public void disableCloseDateInput()
  {
    setButtonStatus('new', DISABLED);
    disableInput = true;
  }
   
    public void enableCloseDateInput(){
        disableInput = false;
    }
 
public void setButtonStatus(String buttonName, Boolean status) {
status = !status;
if (buttonName == 'save') {
isSaveButtonDisabled = status;
} else if (buttonName == 'new') {
isNewButtonDisabled = status;
} else if (buttonName == 'edit') {
isEditButtonDisabled = status;
}
else if(buttonname=='delete')
{
  isDeleteButtonDisabled = status;
}
}
public void disableEnable() {
setButtonStatus('save', ENABLED);
}
public void deleterecord()
{
try
{

CAF_Bank__c cafrecord = new CAF_Bank__c();
cafrecord = [SELECT Id  FROM CAF_Bank__c where Branch_Code__c ='mybranchcode'];
delete cafrecord;
 }
catch(Exception ex1)
{
}
}
}

 Visualforce page:

 <apex:page standardController="CAF_Bank__c" extensions="MyClassnew11">
<script>
 function focussing()
     {
     if(document.getElementById('{!$Component.form1.name}').value.length!=0)
  {
        document.getElementById('{!$Component.form1.name}').focus();
        return false;
      }
      }

  function validate()
  {
    
  var temp=0;
  var dummy=0;
  var tempe=0;
  if(document.getElementById('{!$Component.form1.name}').value.length==0)
  {
            alert('Please enter Bankname');
             document.getElementById('{!$Component.form1.name}').focus();
            return false;
  }
 
   var currName = document.getElementById('{!$Component.form1.iField}').value;
   var myArray = new Array();
    myArray = '{!BankBranchList}'.replace('[','').replace(']','').split(',');
   var i=0;
   if(document.getElementById('{!$Component.form1.name}').value.length!=0)
   {
   for ( i=0; i< myArray.length; i++)
   {
    
    if(trim(myArray[i]) == currName)
     {
       
       alert('Branch code already existed');
       document.getElementById('{!$Component.form1.iField}').focus();
       return false;
      temp=1;
     
     }
    
   }

    if(dummy!=1)
    {
        if(document.getElementById('{!$Component.form1.name}').value.length!=0)
           {
             
          if(document.getElementById('{!$Component.form1.iField}').value.length==0)
          {
            alert('Please enter BranchCode');
           
          document.getElementById('{!$Component.form1.iField}').focus();
           return false;
              temp=1;
            
          }
           else
   if(!(document.getElementById('{!$Component.form1.iField}').value>=0))
      {
         alert('Invalid BranchCode');
         document.getElementById('{!$Component.form1.iField}').focus();
           return false;
         tempe=1;
         }
         }
 
          if(temp!=1)
     fun1();
       }
       }
       }
         function trim(text)
 {
  text = text.replace(/^\s+/, '');
  return text.replace(/\s+$/, '');
 }

</script>

<apex:form id="form1" >
<apex:actionFunction name="fun1" action="{!save}"/>
     <table width="100%"> <tr>
      <td width="17%"></td>
      <td align="left" valign="top" height="45"><font style="font-family:Tahoma, Geneva, sans-serif; font-size:16px; line-height:24px; color:#900;">CAF Bank Details</font>
      </td>
      <td></td>
  </tr></table>                                       
<table width="100%">
    <tr>
      <td width="5%"></td>
      <td>
          <table width="100%" align="center">
          <tr>
                   <td height="30" width="170px"><apex:outputLabel value="Bank Name">
     </apex:outputLabel></td>
                   <td><apex:inputField id="name" value="{!CAF_Bank__c.Bank_Name__c}">
                    <apex:actionSupport event="onkeyup" action="{!disableEnable}" rerender="buttonSection"/>
                   </apex:inputField>
                   </td>
               </tr>
               <tr>
                   <td height="30"><apex:outputLabel value="Branch Code">
      </apex:outputLabel></td>
                   <td><apex:outputPanel id="branchcoding">
     <apex:inputField id="iField" value="{!CAF_Bank__c.Branch_Code__c}">
      <apex:actionSupport event="onkeyup" action="{!disableEnable}" rerender="buttonSection"/>
      </apex:inputfield>
      </td></tr>
      <script>document.getElementById('{!$Component.iField}').disabled = {!disableInput}; </script>
      </apex:outputPanel> 
              
               <tr>
                   <td height="30"><apex:outputLabel value="Branch Name">
     </apex:outputLabel></td>
                   <td><apex:inputField id="bname" value="{!CAF_Bank__c.Branch_Name__c}">
                    <apex:actionSupport event="onkeyup" action="{!disableEnable}" rerender="buttonSection"/>
                   </apex:inputfield>
                   </td>
                 </tr>
                   </table>
<table align="left"><tr><td align="center">

</td></tr></table>

</td><td width="5%"></td></tr>

</table>
<table width="100%"> <tr>
      <td width="12%"></td>
      <td align="left" valign="top" height="45">
        <apex:outputpanel id="buttonSection">
    <apex:commandButton disabled="{!isNewButtonDisabled}" value="New" action="{!create}" />
      <apex:commandButton disabled="{!isEditButtonDisabled}" value="Edit" action="{!disableCloseDateInput}" onclick="focussing()"  rerender="branchcoding, buttonSection"/>
       <apex:commandButton disabled="{!isDeleteButtonDisabled}" action="{!deleterecord}"  value="Delete"/>
       <apex:commandButton disabled="{!isSaveButtonDisabled}" id="button2" action="{!save }" value="Save" onclick="return validate()"  />
      <apex:commandButton value="Cancel"  onclick="clearflds()" reRender="form1"/>
<apex:commandButton action="{!cancel}" value="Exit"/>
</apex:outputpanel>
      </td>
      <td></td>
      </apex:form>
  </tr></table>
</apex:page>

 

inthis line in d controller

cafrecord = [SELECT Id  FROM CAF_Bank__c where Branch_Code__c ='mybranchcode'];

 

Iam trying to compare the current branch code with  d list of branchcode so if  a record with d current branchcode existed in salesforce dbase i want to delete it... but wen i clkick delete iam not able to delete d record...I dont know where iam going wrong..

 

                So plz check out my code and suggest me how could i fulfil my requirement.. of deleting d record with  d curret branchcode which i saved and i wanna delete d same record now...

 

                                                                                                             Thanks&Regards,

                                                                                                                    Anu.....           

bob_buzzardbob_buzzard

cafrecord = [SELECT Id FROM CAF_Bank__c where Branch_Code__c ='mybranchcode'];

 

This is looking for an object where the branch code is the string literal 'mybranchcode'.

 

If you want to find the object where the branch code matches the contents of the variable mybranchcode, use:

 

 

cafrecord = [SELECT Id FROM CAF_Bank__c where Branch_Code__c = :mybranchcode];