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
ManjusrinuManjusrinu 

Displaying records in vf page by clicking buttons

Hi ,
i have a task that when my vf page gets loads i should dispaly accounts and when i click on show contcats button ,the related contacts should dispaly and when i click on show oppournity ,the related oppournities should be displayed .
I wrote the following code and i have no problem on dispalying accounts and contacts.
when i click on show opppournities it is dispalying url doesnt exist
Can anyone help me to figure it out ??
VF-PAGE:
<apex:page controller="AccountContactOppournitydisplay" action="{!getContacts}">
  <apex:form >
      <apex:pageBlock >
        <apex:pageBlockTable value="{!listOfAccounts}" var="r">
            <apex:column value="{!r.Name}"/>
            <apex:column value="{!r.Rating}"/>
        </apex:pageBlockTable>
          <apex:commandButton value="Show contacts" action="/apex//clickactiondisplayContact"/>
        </apex:pageBlock>
   </apex:form>
</apex:page>

CLASS:

public class AccountContactOppournitydisplay
{
 public list<Account>listOfAccounts{get;set;}
 public list<Contact>listOfContacts{get;set;}
 public list<Opportunity>listOfoppournities{get;set;}
  
 public AccountContactOppournitydisplay()
 {
     try
      {
         listOfAccounts=new list<Account>();
        listOfAccounts=[select id,Name,Rating from Account order by Name limit 5];
        system.debug('list of accounts'+listOfAccounts);
       }catch(NullPointerException e)
         {system.debug('null exception');}
  }
      public void  getContacts()
        {
         try{
            listOfContacts=new list<Contact>();
            listOfContacts=[select id,Name from contact where AccountId IN :listOfAccounts];
            system.debug('contactlists'+listOfContacts);
          }
            catch(NullpointerException e)
            {system.debug('Exception raised');}
            }
    
        public void getOppournities()
        {
            try{
          listOfoppournities=new list<Opportunity>();
          listOfoppournities=[select id,Name from Opportunity where account.id IN:listOfAccounts limit 5];
            system.debug('oppournities '+listOfoppournities);
        }
            catch(nullpointerexception e)
            {
                system.debug('Exception raised');
            }
        }
   
}


VF PAGE 2: DISPLAYS CONTACTS

<apex:page controller="AccountContactOppournitydisplay" action="{!getcontacts}" >
  <apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!listOfcontacts}" var="a">
            <apex:column value="{!a.Name}"/>
              <apex:column value="{!a.id}"/>
        </apex:pageBlockTable>
        <apex:commandButton value="Show oppournities" action="/apex//clickactiondisplayOppournity"/>
       </apex:pageBlock>
    </apex:form>
</apex:page>


VF-PAGE3:
<apex:page controller="AccountContactOppournitydisplay" action="{!getOppournities}" >
  <apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable value="{!listOfoppournities}" var="k">
            <apex:column value="{!k.Name}"/>
              <apex:column value="{!k.id}"/>
        </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

ERROR:URL DOES NO LONGER EXIST (ONLY WHEN I CLICK ON SHOW OPPOURNITIES"
ShirishaShirisha (Salesforce Developers) 
Hi Meka,

Greetings!

I can see that you have used the URL which has an extra slash(\) in the url:

 <apex:commandButton value="Show oppournities" action="/apex//clickactiondisplayOppournity"/>

I would suggest you to replace the above line with the below line.

 <apex:commandButton value="Show oppournities" action="/apex/clickactiondisplayOppournity"/>

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri
 
ManjusrinuManjusrinu
Hi Shirisha Pathuri, I have replaced the line that you have mentioned but still it is showing me the same error Can you please help me to solve it out ?