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
affableaffable 

apex code

hi mates, please help me in this sceanario: i have created three custom object book1__c, publisher__c, author__c

In book1__c i gave lookup to two customer objects (author__c, publisher__c) . in visual page am able to get the input feilds of author__c , publisher__ci.e author name, publisher name) . that are lookup feilds  when i use to select the author name from lookup feild and publisher name from lookup and click the search button i should able to display the current book details of assosiated author name and publisher name but am not able to display the desired result. Instead it displays the default book record. please Help me

 

Advance thanks, 

Apex Code: custom Controller:

----------------------------------------

public class BookController

{

String Aname='chaitanya';

String Pname='dinesh';
ID id,id1;

List<book1__c> booklist;
public String getAuthorName()
{
return Aname;
}
//selected List value.
public String getPublisherName()
{
return Pname;
}
public void setAuthorName(String Aname)
{
this.Aname=Aname;
}
public void setPublisherName(String Pname)
{
this.Pname=Pname;
}
public PageReference search()
{
pageReference l = new pageReference ('/apex/bookList');
return l;
}
public PageReference showList()
{
pageReference n= new pageReference('/apex/showList');
return n;
}

public List<book1__C> getBooklist()
{
id=[select name from author__c where name=:Aname].Id;
id1=[select name from publisher__c where name=:Pname].ID;
booklist=[select name,price__c,bookId__c from book1__c where authorId__c=:id and publisherId__c=:id1];
return booklist;
}
}

 

visual page for input :

<apex:page controller="BookController">

<apex:form>

<apex:PageBlock mode="edit">
<apex:pageMessages />
<apex:pageBlocksection >
<apex:pageBlockSectionItem >

<apex:inputField value="{!book.authorId__c}"/>
<apex:inputField value="{!book.publisherId__c}"/>

</apex:pageBlockSectionItem>
<apex:commandButton value="search" action="{!search}"/>
<apex:commandButton value="show" action="{!showList}"/>
</apex:pageBlockSection>
</apex:PageBlock>

</apex:form>

</apex:page>

this visual page is used for displaying output.

 visual Page

-----------------

<apex:page controller="BookController">
<apex:form >
<apex:pageBlock >
<apex:pageBLockSection >
<apex:pageBLockSectionItem >
<apex:dataTable value="{!Booklist}" var="b">

<apex:column value="{!b.name}"/>

<apex:column value="{!b.price__c}"/>

<apex:column value="{!b.bookId__c}"/>
</apex:dataTable>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:PageBlock>
</apex:form>
</apex:page>


Best Answer chosen by Admin (Salesforce Developers) 
affableaffable

Thanks bob for your early reply , Through lookup field which is available in visual page. i have selected the author name and publisher from another lookup field when i select the required feilds . these values are stored in getAuthorname() and setAuthorname(). and record should be retrived of that type.  i dont understand what has gone wrong . please help me

All Answers

bob_buzzardbob_buzzard

In your controller you are using aname and pname as query criteria, but the page doesn't set values for these, so they will always contain the default.

 

<apex:inputField value="{!book.authorId__c}"/>
<apex:inputField value="{!book.publisherId__c}"/>

 

I can't see where book is defined in the controller.

affableaffable

Thanks bob for your early reply , Through lookup field which is available in visual page. i have selected the author name and publisher from another lookup field when i select the required feilds . these values are stored in getAuthorname() and setAuthorname(). and record should be retrived of that type.  i dont understand what has gone wrong . please help me

This was selected as the best answer
affableaffable

thanks bob!!