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
Michael DeluccaMichael Delucca 

Declaring Get ; Set; Variable Issue

Hi All!

I am trying to retrieve input field values from a visualforce page and pass them into the pages controller - 

I've declare the values on the top level of the controller:  public string CreditCard {get; set;}
I then referenced them in the visualforce page:   <apex:inputText label="Credit Card" value="{!CreditCard}" />  
and then tried to pass them into the controller method:  payment.fw1__Credit_Card_Number__c = CreditCard;


However, I get the following error:
       "Error: PaymentResoCtrl Compile Error: Variable does not exist: CreditCard at line 149 column 46"

Aditionally, if I try to declare/instantiate the variable within the method as seen below, I get a null pointer error.
        string CreditCard;

Can anyone help me figure this out? I'd really appreciate help and will definitely upvote any solution.

Thank you everyone! Have a great day! 

 
jigarshahjigarshah
Michael,

Can you share the entire code base so that we can help you troubleshoot and fix the issue?
HARSHIL U PARIKHHARSHIL U PARIKH
I would suggest something along following lines...

E.g., let's say you are showing all the records from Credit_Card__c Obj who has Credit_Card_Name = 'Master'

first create a Apex Class and make a use of Set Method.
 
Public Class MyApexClass{
     String keyWord;
     List<Creit_Card__c> creditcardObj;
     
     Public List<Creit_Card__c> getcreditcardObj(){
        return creditcardObj;
      }
     Public String getKeyword(){
        return keyword;
   }

   Public Void setkeyWord(String str){
        keyword = S;
   }

   Public PageReference showResults(){
      creditcardObj = [Select Id, Credit_Card_Name FROM Creit_Card__c WHERE Credit_Card_Name =:Keyword];
      return null;
   }
​}
visualforce Page would look something like this:
 
<apex:page>
<apex:form>
    <apex:pageBlock>
        <apex:inputText value="{!keyWord}"/>
        <apex:commandButton value="Search" action="{!showResults}"/>
         
        <apex:pageBlockTable value="{!creditcardObj}" var="c">
            <apex:column value="{!c.Id}"/>
            <apex:column value="{!c.Credit_Card_Name}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>

How this works?
On visualforce page when you provide a value inside that text box let's say MASTER then that is thrown into that set method with the parameter of Str and so Str becomes MASTER. Then Keyword becomes MASTER. Why? Because out method says Keyword = Str;

Now, when you click Search button then {!showResults} controller gets called. Once that controller gets called,   creditcardObj = [Select Id, Credit_Card_Name FROM Creit_Card__c WHERE Credit_Card_Name =:Keyword]; query gets run and creditcardObj gets returned via below method.
Public List<Creit_Card__c> getcreditcardObj()
{
                                            return creditcardObj;
  }
Hope this helps and if it helps you solve your question then please mark it as best answer!