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
srikanth sfdcsrikanth sfdc 

Getting contacts and opportunities based on account using visualforce

Hi Guys,

we have a account,contact,opportunity tab as standard object in salesforcce
so my requirement is that

i created a visualforce page 
as i have a inputfield with accountname as lookup for that input field to select any account from lookup
and i have a button side of it as "get details"

as i enter an account into the input filed using lookup and press "get details" button i need to get who are all contacts and opportunities available in that account

can any one help me out of this 


Thanks in advance
RadnipRadnip
So on pushing the get details button fire an action in your class to do a query based on that information and store the results in a list in the class. Then in your visualforce page under your get details button create a table for the results and display the table if the results list has more than one record in it, and thats it. If you want more detail checkout the VisualForce & Apex workbook.
srikanth sfdcsrikanth sfdc
please i need a code to get all existing accounts when i press the lookup
Ravikant kediaRavikant kedia
This is a code for solve your problem .
This code retrive contact information for seleced account similer you can get  opportunities for selected account and then you can use it.

//Page
<apex:page controller="contactController">
    <apex:form >
        <apex:pageBlock title="My Content">
            <apex:pageBlockSection title="My Content Section" columns="2">
                <apex:pageBlockSectionItem>
                    <apex:panelGroup>
                        <apex:outputLabel value="Lookup to an Account" for="theLookup"/>
                        <apex:inputField id="theLookup" value="{!cont.Accountid}"/>
                        <apex:commandButton value="get details" action="{!retriveDetail}"/>
                    </apex:panelGroup>
                </apex:pageBlockSectionItem>
               
               
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>


//Controller



public class contactController
{
  
    public Contact cont{get; set;}
    public contactController()
    {
        cont=new Contact();
   
    }
    public void retriveDetail()
    {
  
        List<Account> accinformation=[select id, (select id, name from contacts), name from Account where id = :cont.AccountId];
        System.debug('************'+accinformation[0].contacts);
   
    }
   
}



RadnipRadnip
@Ravikant you failed to add you paypal account details ;)