+ Start a Discussion
Justin DJustin D 

How to apply this logic to display data in Visualforce page

I am not sure when/whether I should put logic inside Apex class or use Visualforce page to display data.

Here is logic.
Depending on the 
SurveySelection, it would display data (surveytype) differently.

Logic:

If  (SurveySelection__c = 1) {
              Surveytype__c = “final1” and “final2”
} else if (SurveySelection__c = 2) {
              Surveytype__c = “midterm1” and “midterm2”
} else {
              Surveytype__c = “openbooktest1” and “openbooktest2”
}
  

My question is: should I use If Statement inside APEX code like below or should I program inside VF page?​

Here is some Apex code that I have:

 
Public  PageReference   searchStudents()
{
students = [ select
                           LName__c
                           , (select SurveySelection__c from SurveySelections__r )
                           From Student__c ];
 
surveyselections = [select
                             SurveySelection__c
                             From SurveySelection__c ];
 
surveyreference  = [select
                             SurveyType__c
                             From SurveyReference__c ]; 
              Return null;      
}
 
 
JeffreyStevensJeffreyStevens
Pros and Cons of each.  If you put it in apex - it's more read-a-ble, and you have more control.  But if it's in apex - you've got a deployment from sandbox to prodution in order to make any change.  If you put it in Visualforce - it can make the page larger and longer to load, and read-ablility is not as easy as Apex.  But you can edit the logic right in production.

In your specific example - you might think about just making a text formula field and display that field.  That would keep the login in the point and click portion of salesforce, and make the apex and VF simplier.

 
Purushotham YellankiPurushotham Yellanki
Hi,

Always try doing this in Apex, I would suggest if this is a routine process that you want to use in multiple places then its even better putting this piece of Code in some Static Utility Method and call it from you Apex Controller