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
Andre Green 9Andre Green 9 

Need help with APEX and VF code

I have a few questions. Please Please HELP!!!! ASAP
1.  I am trying to develop a account search page.  The results must include the following columns account name, billing state/province, phone and website.  The code I have so far but it is not coming back with the accounts.

2.   Develop a grid of accouunt which can be selected.  Once selected and the "Show Selected Accounts" button is clicked, information from the selected accounts is displayed in the "Selected Accounts" table.  How do I do this and were do I start.  The code I have is is bringing up contacts not accounts. 

3.  Produce a page which displays Accounts and related contact using only one query.

1. CODE
<apex:page controller="theController">
   <apex:form >
      <apex:pageBlock mode="edit" id="block">
         <apex:pageBlockSection title="Search" id="search">
            <apex:pageBlockSectionItem >
               <apex:outputLabel for="searchText">Search Text</apex:outputLabel>
               <apex:panelGroup >
                  <apex:inputText id="searchText" value="{!searchText}"/>
                  <apex:commandButton value="Search!" action="{!doSearch}"  rerender="block" status="status"/>
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
        <apex:actionStatus id="status" startText="Requesting..."/>
        <apex:pageBlockSection title="Results" id="results" columns="1">
           <apex:pageBlockTable value="{!results}" var="l"  rendered="{!NOT(ISNULL(results))}">
              <apex:column value="{!l.name}"/>
              <apex:column value="{!l.email}"/>
              <apex:column value="{!l.phone}"/>
           </apex:pageBlockTable>
        </apex:pageBlockSection>
      </apex:pageBlock>
   </apex:form>
</apex:page>

2.  CODE 
<apex:page controller="wrapperClassController1">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Selected Accounts" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
            <apex:pageBlockTable value="{!contacts}" var="c" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!c.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!c.con.Name}" />
                <apex:column value="{!c.con.Email}" />
                <apex:column value="{!c.con.Phone}" />
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

3.  CODE  APEX

public class accountcontact1
{
    list<AccountWrapper> wraplist=new list<AccountWrapper>();
    public accountcontact1()
    {
       Map<Id, AccountWrapper> accMap=new Map<Id, AccountWrapper>();
       for(account a:[SELECT createdby.name,CreatedbyID,Account.Name,(SELECT      
                name,Contact.FirstName, Contact.LastName 
                FROM Account.Contacts) FROM Account])
       {
     AccountWrapper accWrap=accMap.get(a.CreatedBy.name);  
          // AccountWrapper accWrap=accMap.get(a.CreatedBy.name);
           if (null==accWrap)
           {
              accWrap=new AccountWrapper();
              accMap.put(a.CreatedByname, accWrap);
              accWrap.userid=a.CreatedByid;
           
             // accMap.put(a.CreatedBy.name, accWrap);
              accWrap.username=a.CreatedBy.name;
           }
           accWrap.accounts.add(a);
       }
       wrapList=accMap.values();
   }
   public list<AccountWrapper> getaccounts()
   {
      return wraplist;
   }
   public class AccountWrapper
   {
  public id userid {get; set;} 
      public string username {get; set;}
      public List<Account> accounts {get; set;}
      public AccountWrapper()
      {
         accounts=new List<Account>();
      }
   }
}

3. VF CODE
<apex:page controller="accountcontact1">
<table>
 
  <apex:repeat value="{!accounts}" var="accWrap">
 <tr> <td>
  <apex:outputText value="User ID : {!accWrap.username}"/>
</td></tr>
   <apex:repeat value="{!accWrap.accounts}" var="acc">
<tr><td>
<apex:outputText value="Account : {!acc.Name}"/>
</td></tr>
      <apex:repeat value="{!acc.contacts}" var="cont">
<tr><td>
<apex:outputText value="Contact : {!cont.Name}"/>
</td></tr>
 
</apex:repeat>
<tr><td><hr/></td></tr>
</apex:repeat>
 
</apex:repeat>
</table>
</apex:page>
Shashikant SharmaShashikant Sharma
Hi,

Are you not able to achieve it with 3rd code piece that you have shared ? What is the exact issue that you are facing ?

Thanks
Shashikant
Andre Green 9Andre Green 9
The 3rd one.  I am trying to display Accounts and related contact using only one query.  What did you come up with for the first two?
Shashikant SharmaShashikant Sharma
Hi Andre,

I would want you to share more details sepacific to each page and class. Then would help me more to understand it.

Thanks
Shashikant