+ Start a Discussion
Hari nadh babu EluruHari nadh babu Eluru 

Getting Error in Min Max Age result showing in another page

Vf code page 1
<apex:page controller="age">
<apex:form >
<apex:outputLabel >Enter Min Age</apex:outputLabel>
<apex:inputText value="{!p}"/>
<apex:commandButton value="Click me" action="{!ageBut}"/>
</apex:form>
</apex:page>

Apex code Page 1
public class age {

    public PageReference ageBut() {
        PageReference pr = new PageReference ('https://93com4-dev-ed--c.visualforce.com/apex/Max_Age?abc='+p);
        return pr;
    }
    public String p { get; set; }
}

Vf code page 2
<apex:page controller="Max_Age">
<apex:form >
    {!z.name}
    {!z.Age__c}
</apex:form>
</apex:page>

Apex code page 2
public class Max_Age {

    public Student__c z { set; get; }
    
    public Max_Age(){
        string k = ApexPages.currentPage().getParameters().get('abc');
        
     z = [SELECT Name, Student_Id__c, Age__c FROM Student__c WHERE Student_Id__c=:k];
    }
}

The above image was getting error in codes
Error
Best Answer chosen by Hari nadh babu Eluru
Suraj Tripathi 47Suraj Tripathi 47

Hi Hari,

Please try the below code:


public class Max_Age {
public Student__c z { set; get; }
public Max_Age()
{
string k = ApexPages.currentPage().getParameters().get('abc');
if(k){
Student__c studentobj = new Student__c();
studentobj = [SELECT Name, Student_Id__c, Age__c FROM Student__c WHERE Student_Id__c=:k];
if(studentobj!= null){
z = studentobj;
}
      }
}
}

VF PAge:

<apex:page controller="Max_Age">

<apex:form >
    <apex:outputPanel rendered="{!NOT(ISNULL(z))}">

{!z.name} {!z.Age__c}

</apex:outputPanel>
</apex:form>

</apex:page>

if you need any assistance, please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Suraj Tripathi

All Answers

Maharajan CMaharajan C
Hi Hari,

Please try the below code:
 
public class Max_Age {

    public Student__c z { set; get; }
    
    public Max_Age(){
        string k = ApexPages.currentPage().getParameters().get('abc');
        
		list<Student__c> students = [SELECT Name, Student_Id__c, Age__c FROM Student__c WHERE Student_Id__c=:k limit 1];
		
		if(!students.IsEmpty())
			z = students[0];
    }
}

Thanks,
Maharajan.C
william lee 75william lee 75
Suraj Tripathi 47Suraj Tripathi 47

Hi Hari,

Please try the below code:


public class Max_Age {
public Student__c z { set; get; }
public Max_Age()
{
string k = ApexPages.currentPage().getParameters().get('abc');
if(k){
Student__c studentobj = new Student__c();
studentobj = [SELECT Name, Student_Id__c, Age__c FROM Student__c WHERE Student_Id__c=:k];
if(studentobj!= null){
z = studentobj;
}
      }
}
}

VF PAge:

<apex:page controller="Max_Age">

<apex:form >
    <apex:outputPanel rendered="{!NOT(ISNULL(z))}">

{!z.name} {!z.Age__c}

</apex:outputPanel>
</apex:form>

</apex:page>

if you need any assistance, please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Suraj Tripathi

This was selected as the best answer