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
Baishaki DasBaishaki Das 

Visualforce page not displaying values from related table

I have a custom object course__c. Requirement: When I enter the course name and press button, it should search the related deals from object Training_Deal__c.Course and Training_Deal are connected by MDR. If there are records matching the course name, it should show the deal details, else throw error:no records found. But whenever I enter non matching course name, it is not throwing error and showing the same deal details for all the courses in the database.
Appreciate any help to fix this.

public class Dealsclass { public string Courses{set;get;}
public static list<Training_Deal__c> results{get;set;}
//public static list<Course_Master__c> cours{get;set;}
public Dealsclass(){ results=null; //cours=null; }
public static void searchdeals(){
//List<Course_Master__c> cours=[SELECT Course_Name__c From Course_Master__c];
results=[SELECT Discount_Percentage__c,Discount_Reason__c,Fees_Paid_by_Student__c,Deal_Risk_Status__c,Course__r.Name FROM Training_Deal__c WHERE Course__r.Name IN ('Java')]; if(results.size()==0){
ApexPages.Message msg1= new ApexPages.Message(ApexPages.Severity.ERROR,'No results Found');
ApexPages.addMessage(msg1); } } }
Visualforce page :
<apex:page controller="Dealsclass" >
<apex:form >
<apex:pageBlock >
<apex:outputPanel >
<apex:pageMessages ></apex:pageMessages> </apex:outputPanel>
<apex:outputLabel >
Course to search</apex:outputLabel>
<apex:inputText value="{!Courses}"/>
<apex:commandButton value="search" action="{!searchdeals}"/> <apex:pageBlockTable value="{!results}" var="d">
<apex:column value="{!d.Discount_Percentage__c}"/> <apex:column value="{!d.Discount_Reason__c}"/>
<apex:column value="{!d.Fees_Paid_by_Student__c}"/> <apex:column value="{!d.Deal_Risk_Status__c}"/>
<apex:column value="{!d.Course__r.Name}"/> </apex:pageBlockTable>

shekhar 46shekhar 46
hi, do u know what is problem with this code.
i m trying to show trainer deals  object data & trainer master object data on sameVFP. , it is showing only training deals(details obj) data  but not trainer master data.(master objt)
public class trainingDealclass {
  public list<Trainer_master__c> traininglist{get;set;}     public trainingdealclass(){
        traininglist= [SELECT First_name__c, Last_name__c, Education__c,SELECT Course_c  FROM CRN_Training_deals__r)
                      FROM Trainer_master__c LIMIT 10];
<apex:page controller="TrainingDealClass">
    <apex:Pageblock title="training details">
        <apex:pageblocktable value="{!traininglist}" var="a">
            <apex:column value="{!a.First_name__c}"/>
            <apex:column value="{!a.Last_name__c}"/>
            <apex:column value="{!a.Education__c}"/>
         <apex:pageBlockTable value="{!a.CRN_Training_deals__r}" var="b">  
            <apex:column value="{!b.Course__c}"/>