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
Gopal ChatGopal Chat 

How to create a master detail relationship between account and opportunity using visualforce page.when we click on an account related opportunity will display

How to create a master detail relationship between account and opportunity using visualforce page.when we click on an account ,related opportunity will display 
if anyone has the answer please mail me on amuraghav14@gmail.com
 
Ajay K DubediAjay K Dubedi
Hi Gopal,

Please see the code below:-
<apex:page controller="ShowAccWithContactController" sidebar="true" showHeader="false">
    <apex:form >
        <apex:pageBlock title="Accounts List">
          <b>  <apex:outputLabel >On Clicking the Account Name you will see the Opp associated..</apex:outputLabel></b><br/><br/>
        <apex:repeat value="{!accounts}" var="acc">
           <b> <apex:commandLink value="{!acc.Name}" action="{!showOpps}" onclick="click()">
                 <apex:param name="accountId" value="{!acc.id}" assignTo="{!accountId}"/>
                 <!--apex:outputText value="{!acc.shippingcity}"></apex:outputText-->
            </apex:commandLink></b>
            <br/><br/> 
        </apex:repeat>
               
    </apex:pageBlock>
        <apex:pageBlock title="Opp List" id="OppBlock" rendered="{!conenable}"> 
        <!--apex:pageBlockTable value="{!contacts}" var="con"-->
        <apex:repeat value="{!Opps}" var="op">
            <apex:outputLabel rendered="{!enable}">
            <apex:outputField value="{!op.name}">
                </apex:outputField></apex:outputLabel>
            </apex:repeat>
    </apex:pageBlock>
</apex:form>
</apex:page>
public class ShowAccWithContactController {
    
    public boolean enable{get;set;}
    public boolean conenable{get;set;}
    public boolean disable{get;set;}
    public list<account> accounts{get;set;}
    public String accountId {get; set;}
    public list<Opportunity> Opps{get;set;}
    
    public ShowAccWithContactController()
    {
        string acc='select id,name,shippingcity from account limit 20';
        accounts=database.query(acc);
        enable=true;
        conenable=false;
        disable=false;
    }
    
    public PageReference showOpps() {
        conenable=true;
        enable=true;
        disable=false;
        Opps= [Select id, name from Opportunity where AccountId = :accountId];
        return null;
    }
}

Please mark it as best if found helpful.

Thanks
Ajay
Gopal ChatGopal Chat
thanks ajay
Ajay K DubediAjay K Dubedi
Sure Gopal, i hope you found it helpful.
Thanks
Gopal ChatGopal Chat
sir any job for salesforce developer fresher
Ajay K DubediAjay K Dubedi
Please share resume at Career CA -
<career@cloudanalogy.com>