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

SOQL Query help on lookup field which is a Search field in page

Hi All,
I have a requirement to search Course Name in Visual force page.
I have to return all Training Deal Object values based on the course name entered in the search field value.
Course Master: Master Table
Training Deal:Detail Table

Training Deal has a master-detail datatype Course__c field
when I query the Training Deal table I get RecordID of the Course__c field instead of the Course Code value.
How to pass this RecordID in the query to Course Master and get the search results.
I have tried many combinations in below apex class....sorry for the messy looking queries..
VF Page
<apex:page controller="searchname1">
  <apex:form >
   <apex:pageblock id="one" >
    <apex:pageblockSection >
    <apex:pageblocksectionitem >
       <apex:outputlabel >Course to Search</apex:outputlabel>
         <apex:inputtext value="{!name}"/>
         <apex:commandButton value="go" action="{!search}"/>
           <apex:pageBlock rendered="{!searched}" >
            <apex:pageblocktable value="{!lstcourse}" var="c">
            <apex:column value="{!c.Name}"/>
             <apex:column value="{!c.Course_Name__c}"/>
            <apex:pageblockbuttons >
             <apex:commandButton value="edit" action="{!edit}"/>

Apex Class:

public with sharing class searchname1 {

    public PageReference edit() {
        return null;

   public String name { get; set; }
    public list<Training_Deal__c> lstdeal { get; set; }
    public list<Course_Master__c> lstcourse { get; set; }
    public boolean searched{get;set;}
    //default constructor
    public searchname1(){
    string namestr=apexpages.currentpage().getparameters().get('name');
    public PageReference search() {
     string searchstr1=('%'+name+'%');
      lstdeal=[select Name,Course__c from Training_Deal__c ];
      //lstcourse=[select Name,Course_Name__c from Course_Master__c where ID=:Training_Deal__c.Course__c];
    /* lstcourse= [select Name,Course_Name__c from Course_Master__c 
                 where Course_Name__c like :searchstr1 limit 10 ];
     for(Course_Master__c crs:lstcourse )
         lstdeal=[select Name,Course__c from Training_Deal__c where Course__c LIKE :crs.Course_Name__c ];
    //lstdeal=[select Name,Course__c from Training_Deal__c where Course__c like searchstr1 limit 10 ];
        return null;

PriyaPriya (Salesforce Developers) 

Hi Surekha,

This question has been already posted :-

So I have to mark this as duplicate. Community will try to answer your query on the previous post. 


Priya Ranjan