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
Mathieu CanyMathieu Cany 

Beginner question : Display data in a table with conditions



I have a very basic problem in the development of my customized page. I would like create a summary table with different information from my environment.  At the beginning i used the Standard controller. But now i would like to have access to data on different area not just Opportunity or Account data. I would like to have information about this both place.


So i have decided to create me costumed controller for make a SOQL query and find all information that I need : (Stop me if have already made a mistake)


But i don't know how to have an effective Appex Class and 100% coverage code :


public class myControllerExtension {
      public List<Account> Listaccount()


// Exemple of data that i'm looking for


      List<Account>  accounts = [Select Id, Name, BillingCountry from Account];
      return accounts;


    public static testMethod void Listaccount() {


// How i could test this simple Query ? And all next that i'll create




If there is a way to have an access of data from Opportunity and account in the same time without developing my own Controller let me know :)



A second basic question but i didn't find how to do that, how could I have a sum of all fields in my table?


I have already spent a lot of time on guides without success.


Thanks a lot

Ritesh AswaneyRitesh Aswaney

Depending on what you're trying to do, you can use the Opportunity Standard Controller, and access Account Field via Relationship references


eg. {!Opportunity.Account.Name}


If you need to use a SOQL query, 


//returns an account and all associated opportunities

Select Id, Name, (Select Id, Name from Opportunities) from Account


//returns account and opportunity fields for one opportunity

Select Id, Name, Account.Name from Opportunity

Mathieu CanyMathieu Cany

Thanks !


I could find information in my table with this way of functioning : {!Opportunity.Account.Name}


Now if I just want to have a list on my table depending on the value of a custom field :


Classer_le_dossier_dans_les_historiques__c (A chekbox)


I just want to display my information if Classer_le_dossier_dans_les_historiques__c have been tick. (True), have I to create a SOQL query or there is a possibility to display this kind of condition directly on my Visual page like that:


 <apex:pageBlockTable value="{!Opportunities}" var="a"  // IF Classer_le_dossier_dans_les_historiques__c ="TRUE" >


I think developers who will see this kind of line will be probably chocked :)



If I have to create my SOQL query; the way of find my information won't be a problem because It is the same typology than in SQL. The problem will be the test code for have the right to deploy it in my production environment. If you have an example of a test for SOQL query I’ll probably be able to adapt it at my need.


Thanks for your support.