You need to sign in to do that
Don't have an account?
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>
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
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.
I can't see where book is defined in the controller.
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
thanks bob!!