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
PardhuPardhu 

Compare value give in vf page to value already stored in custom object as record.

Hello.. Iam newbiee to salesforce.com..

i have a problem in comparing the the value that i give in vf to the value already stored in an object.

 

My programming seems to be Clumpzy..Plz humour me..

 

Here is the code which i have written..

 

vf page :- 

 

  <apex:page controller="test3con" showHeader="false" sidebar="false">

        <apex:form >
                <apex:sectionHeader title="Game ON!!!" subtitle="Salesforce A Day..."/>
                      <apex:pageblock >

                 <apex:pageblockTable value="{!id}" var="g" >

              <apex:column value="{!g.Question__c}"/><br/>

                     </apex:pageblockTable><br/>
              Answ:- <apex:inputText value="{!ans}"/> <br/><br/>
               <apex:messages />

<br/>
                    <apex:commandButton value="Submit" action="{!click}"/> &nbsp;&nbsp;
                 <apex:commandButton value="Refresh" action="{!refresher}"/>

         </apex:pageblock>
      </apex:form>
</apex:page>

 

 

Controller :-

 

 

public class test3con {

public PageReference refresher() {

pagereference pr = new pagereference('/apex/test3');

return pr;
}


public PageReference click() {
project__c g = new project__c();


if( g.Answer__c == ans ){

ApexPages.Message errMs= new ApexPages.Message(ApexPages.Severity.ERROR, 'Correct Answer');
ApexPages.addMessage(errMs);
insert g;
system.debug('----------'+g.Answer__c);
return null;
}
else
{
ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Wrong Answer');
ApexPages.addMessage(errMsg);
return null ;
}

 

}
public String ans { get; set; }


public List<project__c> id {get; set;}
Public test3con() {

id = [SELECT Question__c FROM project__c where ID ='a0090000009huAz' ];

}

}

 

ID ='a0090000009huAz'   this is record id in the object "project__C"

Iam mission out something herer..which iam unable to understand. iam unable to compare the value which i give in that textfeild..to that value stored in that object..as record....  

 

Kindly help me out in solving this problem

 

Regards

 

Pardha saradhi.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
kriskkrisk

Copy and paste my code in your controller class and change my Id with your Id(a0090000009huAz). That should work for you.

 

You have to compare the Answer you input on screen with Answer from the Project object. 

 

That is why I am selecting Answer__c also from Project object.

 

In your earlier post you are creating a new project object and not reading project object using Id

 

p.Question__c means you are selecting that field from Project p. That shouldn't be that big of a deal so use my code

 

 

All Answers

kriskkrisk

You are instatiating a new Project object instead of using the one you are going read out of your org using id. 

 

Use this code instead for test3con

 

test3con:

 

public class test3con {
public PageReference refresher() {

pagereference pr = new pagereference('/apex/test3');

return pr;
}

Public test3con() {
id = [SELECT p.Question__c, p.Answer__c FROM Project__c p where ID ='a0090000009huAz' Limit 1];
}

public PageReference click() {
project__c g = new project__c();


if( id.Answer__c.equals(ans) ){

ApexPages.Message errMs= new ApexPages.Message(ApexPages.Severity.ERROR, 'Correct Answer');
ApexPages.addMessage(errMs);
insert g;
system.debug('----------'+g.Answer__c);
return null;
}
else
{
ApexPages.Message errMsg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Wrong Answer');
ApexPages.addMessage(errMsg);
return null ;
}

}
public String ans { get; set; }

public project__c id {get; set;}

}

 

Don't forget to give Kudos to someone that helped you solve your problem

PardhuPardhu

my subject is not regarding comparing picklist values...

 

Iam acutally trying to  compare the value which i gave in vf page.   and that shld be compared to the feild value which i already gave it object. (already existed)

 

if both of the match. the message shld be shown as COrrect answer.

 

Hence..i querried the question__C from object and displayed it on vf page. ..and i created a inputtext feild.  

 

Theres is another  Answer__C  in object..wher i gave my value as   "spring"..

Now...if i try to give the same thing. as "spring" in vf page in taht textfield which i created...and when i press submit button. it should compare with that value in Answer__C which is on the object and it shld display a message saying that..its correct answer or not...

i THInk my question is clear to u....just help me out with this thing :)

 

 

And finally brother..  I didnt understand what exactly this line do..

id = [SELECT p.Question__c , p.Answer__c FROM project__c p  where ID ='a0090000009huAz' ];

 

i mean...how exactly the operation go on when u use p.Question__C   ??    function of p.?

 

 

 

 

REgards

 

Pardhu.

kriskkrisk

Copy and paste my code in your controller class and change my Id with your Id(a0090000009huAz). That should work for you.

 

You have to compare the Answer you input on screen with Answer from the Project object. 

 

That is why I am selecting Answer__c also from Project object.

 

In your earlier post you are creating a new project object and not reading project object using Id

 

p.Question__c means you are selecting that field from Project p. That shouldn't be that big of a deal so use my code

 

 

This was selected as the best answer
PardhuPardhu

Hey Thanks bro...done.!!...