0

I have 3 objects like Account, Custom_object__1 and custom Object2__c. Both the custom objects has a master detail relationship with Account. I would like to build a custom visualforce search page where I can search by Account Name and all the child records will be shown in the tables below with editable option.

Any references for this approach is really appreciated.

4 Answers 4

2

Try using the following controller and vf page Controller:

public class democlass {
 public string searchboxstring{get; set;}
 public list<contact> result {get; set;}

 public democlass()
 {
  result = new list<Contact>();
 }
 public void searchbox(){
  result=new List<Contact>();
  result=[select ID,Name, account.name from Contact where account.Name =:searchboxstring];
 }
}

Vf Page:

<apex:page controller="democlass">  
<apex:form >
<apex:pageBlock >

 <apex:pageBlockSection columns="2">
 <apex:inputText value="{!searchBoxstring}" label="Search"/>
   <apex:commandButton value="Search" action="{!searchbox}" >

  </apex:commandButton>

    <apex:pageblockTable value="{!result}" var="wl">
     <apex:column value="{!wl.name}"/>
      <apex:column value="{!wl.account.name}"/>
      <apex:column value="{!wl.id}"/>
    </apex:pageblockTable>   
  </apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page> 

This will display contacts of searched account on the page. Let me know if this helps.

0

I would use 2 wrap classes, representing the custom objects as well as their modified state with a boolean bModified.

public class wrap1 {
  public Custom_Object_1__c obj { get; set; }
  public Boolean bModified { get; set; }

  public wrap1(Custom_Object_1__c obj) {
    this.obj = obj;
    this.modified = false;
  }
}

So you can populate two different lists of wrap1 and wrap2 with SOQL Query :

list<wrap1> l1 = new list<wrap1>();
for(Custom_Object_1__c obj : /*your query*/) {
    l1.add(new wrap1(obj));
}

When the user changes something on a table, you change bModified to true (calling an action with the index of the wrap as parameter)

When the user clicks "Save", you check which wrap1 have bModified to true, and populate another list that you will update. You have to do that because if your query displays 100 records, and the users modifies only 2 of them, the scope of the update will be only those two records, not all the 100 ones.

Be sure to escape the value of the account name entered in the search module, for security reasons. Also, beware of the view state in your page... The more you have wrap1 and wrap2 instances, the bigger the view state will be.

0

I think your query having problem.. Please try this query

result=[select ID, Name, account.name from Contact where Name =:searchboxstring

0

//try this code

public class democlass {
 public string searchboxstring{get; set;}
 public list<contact> result {get; set;}
 public string checkstring;
 public democlass()
 {
  result = new list<Contact>();
 checkstring= apexpages.currentpage.getParameters.get('searchboxstring');
 }
 public void searchbox(){
  result=new List<Contact>();
  result=[select ID,Name, account.name from Contact where account.Name =:checkstring];
 }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .