• affable
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 5
    Replies

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>


hi mates  please help in below Scenario;

Scenario: i have visual page consists of three feilds name,price,address and save button. when i click on save button these fileds information must be stored  as record in custom tableor object Book1__c .

please provide code for this Scenario.

 

 

I have tried with some smple code but its not working am new to apex Language;

 

public class Book3
{
string name=null;
Double Bookprice=null;
Integer Bookid=null;
public Book1__c newbook;
public Book3()
{
 ID id=ApexPages.CurrentPage().getParameters().get('id');
 newbook = (id == null)?new Book1__c():
 [select Bookid__c,name,Bookprice__c from Book1__c where id=:id];
}

public String getName()
 {
 return name;
 }
 public void setName(String name)
 {
  this.name=name;
 }
public Integer getNumber()
 {
 return Bookid;
 }
public void setNumber(Integer Bookid)
{
 this.Bookid=Bookid;
}  
  public Double getprice()
 {
 return Bookprice;
 }
public void setprice(Double  Bookprice)
{
 this.Bookprice=Bookprice;


public Book1__c getbook()
{
 return newbook;
 }
public pageReference save()
{
 try{
  upsert newbook;
  }
  catch(System.DmlException e)
  {
  ApexPages.addMessages(e);
  return null;
  }
  return null;
  }
  }

 

 


visual page
-----------
<apex:page controller="Book3">
<apex:form >
<apex:pageBlock title="This is sample" mode="edit">
<apex:pageMessages />
NAME: &nbsp;&nbsp;&nbsp;&nbsp;
<apex:inputText value="{!Name}"/>
<br/>
BOOKID:&nbsp;&nbsp;&nbsp;&nbsp;
<apex:inputText value="{!Number}"/>
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlock>
</apex:form>
</apex:page>

i have created emp2__c object for employees and dep2__c object  for department. ,  emp2__c is related to dep2__c (lookup). if i select deptName and press btton go i should view the records of corresponding employees associated with department name . but  instead am getting ids. help me in this issue.

 

controller:

public class departmentConrtroller
{
List<dept2__c> deptList;// departmentList
List<emp2__c> employeesList;//employeeList

String departmentNumber='10';
public departmentConrtroller()
{
 deptList =[select Id,name,dept2No__c,Location__c from dept2__c];
 }
//select options
public List<SelectOption> getdepartmentItems()
{

List<selectOption> options = new List<selectOption>();
 
for(dept2__c dept : deptList)
 {
  String departmentNumber1 =String.valueOf(dept.dept2No__c);
  options.add(new selectOption(departmentNumber1,dept.name));
 }
 return options;
}
 
 public String getdepartmentNumber()
 {
 return departmentNumber;
 }
 public void setdepartmentNumber(String departmentNumber)
 {
 this.departmentNumber=departmentNumber;
 }
 public List<emp2__c> getemployees()
 {
  Id id=[select Id from dept2__c where dept2No__c=:departmentNumber].ID;
  employeesList=[select name,employeeId__c,  salary__c,Address__c from emp2__c where dept2No__c=:id];
  return employeesList;
 }
 public PageReference go()
 {
 return null;
 }
 }

 

visualpage: sx

 

 

<apex:page controller="departmentConrtroller">
<apex:form >
<apex:selectList value="{!departmentNumber}">
<apex:selectOptions value="{!departmentItems}"/>
</apex:selectList>
<apex:commandButton value="go" action="{!go}"/ >

</apex:form>
<apex:outputText value="{!employees}"/>
</apex:page>

hi am unable to resolve these issues  please  help me :

 

I have created two custome objects emp and dept1 , and i took master realation ship in employee table and related to dept1 table . when am able to write customer controller and visual page am getting following errors.

 

Error: Compile Error: unexpected token: '(' at line 13 column 70

public class SController
{
Integer departmentNumber;
List<emp__c> employees;
public Scontroller ()
{
employees=[select departmentNumber__c,id__c,sal__c,Name from emp__c where departmentNumber__c=:departmentNumber];
}
public Integer getDepartmentNumber()
 {
 return departmentNumber;
 }
public void setDepartmentNumber(ApexPages.currentPage.getParameter.get('departmentNumber'))
   {
   this.departmentNumber=ApexPages.currentPage.getParameter.get('departmentNumber');
   public List<emp__c>  getEmployees()
   {
   return employees;
   }
 public PageReference go()
  {
  return null;
  }
  }

 

 

 

ERROR: there is no SController Apex class Create: public class SController or create apex class public "sharing with" SController.

 

<apex:Page controller="SController">
<apex:form>
<apex:pageBlock title="employeeslist of current department">
<apex:pageBlockSection>
<apex:inputField value="{!dept1__c.number__c}" id="departmentNumber"/>
<apex:commandButton value="go" action="{!go}"

reRender="departmentNumber"/>
</apex:pageBlockSection>
<apex:pageBlockSection>
<apex:pageBlockTable title="current employees" value="{!employees}"

var="e">
<apex:column value="{!e.sal__c}"/>
<apex:column  value="{!e.id__c}"/>
<apex:column  value="{!e.Name}"/>
<apex:column  value="{!e.departmentNumber__c}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>