• Baishaki Das
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
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.

Controller:
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>

</apex:pageBlock>
</apex:form>
</apex:page>