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
bhanu reddy 24bhanu reddy 24 

how to got records opportunity to contact by using soql query

Best Answer chosen by bhanu reddy 24
Brahmaiah GantaBrahmaiah Ganta
Visualforce Page
<apex:page controller="VFPageOppStageNameQualifyCon" >
    <apex:form >
      <apex:pageBlock >
       <apex:pageBlockSection title="Qualified Opportunities">
       <apex:pageBlockTable value="{!oppQualifyList}" var="opp">
          <apex:column value="{!opp.Name}" />
          <apex:column value="{!opp.StageName}" /> 
          <apex:column headerValue="Contact Name" >
           <apex:repeat value="{!opp.OpportunityContactRoles}" var="con">
               <apex:outputText value="{!con.Contact.Name}" />
           </apex:repeat>
          </apex:column>   
        </apex:pageBlockTable> 
       </apex:pageBlockSection>
       <apex:pageBlockSection title="Prospecting Opportunities">
       <apex:pageBlockTable value="{!oppProspectingList}" var="opp">
          <apex:column value="{!opp.Name}" />
          <apex:column value="{!opp.StageName}" /> 
          <apex:column headerValue="Contact Name" >
           <apex:repeat value="{!opp.OpportunityContactRoles}" var="con">
               <apex:outputText value="{!con.Contact.Name}" />
           </apex:repeat>
          </apex:column>   
        </apex:pageBlockTable> 
       </apex:pageBlockSection>
        <apex:pageBlockSection title="NeedsAnalysis Opportunities">
       <apex:pageBlockTable value="{!oppNeedsAnalysisList}" var="opp">
          <apex:column value="{!opp.Name}" />
          <apex:column value="{!opp.StageName}" /> 
          <apex:column headerValue="Contact Name" >
           <apex:repeat value="{!opp.OpportunityContactRoles}" var="con">
               <apex:outputText value="{!con.Contact.Name}" />
           </apex:repeat>
          </apex:column>   
        </apex:pageBlockTable> 
       </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>
</apex:page>

Controller
public class VFPageOppStageNameQualifyCon {
    Public List<Opportunity> oppList{get;set;} 
    public List<Opportunity> getoppQualifyList(){
        oppList = new List<Opportunity>();
        oppList = [SELECT Name,StageName,(SELECT ContactId,Contact.Name from OpportunityContactRoles) FROM Opportunity where StageName = 'Qualification'];
          return oppList;        
    }
     public List<Opportunity> getoppProspectingList(){
        oppList = new List<Opportunity>();
        oppList = [SELECT Name,StageName,(SELECT ContactId,Contact.Name from OpportunityContactRoles) FROM Opportunity where StageName = 'Prospecting'];
          return oppList;        
    }
    public List<Opportunity> getoppNeedsAnalysisList(){
        oppList = new List<Opportunity>();
        oppList = [SELECT Name,StageName,(SELECT ContactId,Contact.Name from OpportunityContactRoles) FROM Opportunity where StageName = 'Needs Analysis'];
          return oppList;        
    }
}
Repeat the Same steps Like i have add in vf and controller.Just what you have to do is change the "methodName" and "stageName" value in soql query of Controller and add pageblocksection for each method.

Let me Known if we have any queries. 

All Answers

Brahmaiah GantaBrahmaiah Ganta
Hi,
Check it may be can helps
Select id,(select ContactId,Contact.Name from OpportunityContactRoles) from opportunity

 
bhanu reddy 24bhanu reddy 24
thank you so much responding me
bhanu reddy 24bhanu reddy 24
how to display only (stagename)qualification records, contact name record in opportunity object in vf pageby using page block table
bhanu reddy 24bhanu reddy 24
can you plzz help me
Brahmaiah GantaBrahmaiah Ganta
Hi Bhanu,
Try the below code .Let me Known it helped or not?
Visualforce Page
<apex:page controller="VFPageOppStageNameQualifyCon" >
    <apex:form>
      <apex:pageBlock>
       <apex:pageBlockTable value="{!oppQualifyList}" var="opp">
          <apex:column value="{!opp.Name}" />
          <apex:column value="{!opp.StageName}" /> 
          <apex:column headerValue="Contact Name" >
           <apex:repeat value="{!opp.OpportunityContactRoles}" var="con">
               <apex:outputText value="{!con.Contact.Name}" />
           </apex:repeat>
          </apex:column>   
        </apex:pageBlockTable> 
      </apex:pageBlock>
    </apex:form>
</apex:page>

Apex class Controller
public class VFPageOppStageNameQualifyCon {
    Public List<Opportunity> oppList{get;set;} 
    public List<Opportunity> getoppQualifyList(){
        oppList = new List<Opportunity>();
        oppList = [SELECT Name,StageName,(SELECT ContactId,Contact.Name from OpportunityContactRoles) FROM Opportunity where StageName = 'Qualification'];
          return oppList;        
    }
}

Please Let me Known.
Brahmaiah GantaBrahmaiah Ganta
One more thing have we created any relationship between Opportunity and Contact.
 
bhanu reddy 24bhanu reddy 24
thank you so much responding me
bhanu reddy 24bhanu reddy 24
this is correct but my requirement not only qualification table  iam showing all stage names but individual table how to write 
bhanu reddy 24bhanu reddy 24
table by table  will display in one vf page
prosoecting table next qualifiction table (ext.......) all stages will display how to write 
Brahmaiah GantaBrahmaiah Ganta
Visualforce Page
<apex:page controller="VFPageOppStageNameQualifyCon" >
    <apex:form >
      <apex:pageBlock >
       <apex:pageBlockSection title="Qualified Opportunities">
       <apex:pageBlockTable value="{!oppQualifyList}" var="opp">
          <apex:column value="{!opp.Name}" />
          <apex:column value="{!opp.StageName}" /> 
          <apex:column headerValue="Contact Name" >
           <apex:repeat value="{!opp.OpportunityContactRoles}" var="con">
               <apex:outputText value="{!con.Contact.Name}" />
           </apex:repeat>
          </apex:column>   
        </apex:pageBlockTable> 
       </apex:pageBlockSection>
       <apex:pageBlockSection title="Prospecting Opportunities">
       <apex:pageBlockTable value="{!oppProspectingList}" var="opp">
          <apex:column value="{!opp.Name}" />
          <apex:column value="{!opp.StageName}" /> 
          <apex:column headerValue="Contact Name" >
           <apex:repeat value="{!opp.OpportunityContactRoles}" var="con">
               <apex:outputText value="{!con.Contact.Name}" />
           </apex:repeat>
          </apex:column>   
        </apex:pageBlockTable> 
       </apex:pageBlockSection>
        <apex:pageBlockSection title="NeedsAnalysis Opportunities">
       <apex:pageBlockTable value="{!oppNeedsAnalysisList}" var="opp">
          <apex:column value="{!opp.Name}" />
          <apex:column value="{!opp.StageName}" /> 
          <apex:column headerValue="Contact Name" >
           <apex:repeat value="{!opp.OpportunityContactRoles}" var="con">
               <apex:outputText value="{!con.Contact.Name}" />
           </apex:repeat>
          </apex:column>   
        </apex:pageBlockTable> 
       </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>
</apex:page>

Controller
public class VFPageOppStageNameQualifyCon {
    Public List<Opportunity> oppList{get;set;} 
    public List<Opportunity> getoppQualifyList(){
        oppList = new List<Opportunity>();
        oppList = [SELECT Name,StageName,(SELECT ContactId,Contact.Name from OpportunityContactRoles) FROM Opportunity where StageName = 'Qualification'];
          return oppList;        
    }
     public List<Opportunity> getoppProspectingList(){
        oppList = new List<Opportunity>();
        oppList = [SELECT Name,StageName,(SELECT ContactId,Contact.Name from OpportunityContactRoles) FROM Opportunity where StageName = 'Prospecting'];
          return oppList;        
    }
    public List<Opportunity> getoppNeedsAnalysisList(){
        oppList = new List<Opportunity>();
        oppList = [SELECT Name,StageName,(SELECT ContactId,Contact.Name from OpportunityContactRoles) FROM Opportunity where StageName = 'Needs Analysis'];
          return oppList;        
    }
}
Repeat the Same steps Like i have add in vf and controller.Just what you have to do is change the "methodName" and "stageName" value in soql query of Controller and add pageblocksection for each method.

Let me Known if we have any queries. 
This was selected as the best answer
Brahmaiah GantaBrahmaiah Ganta
Let me Known are you able to do the next steps or will i help
 
bhanu reddy 24bhanu reddy 24
wow really your awesome thank you so much 
bhanu reddy 24bhanu reddy 24
i have one dought  it is not possible all stages by using one soql query?
Brahmaiah GantaBrahmaiah Ganta
It is not Possible with one Query,but you want do with single query try with below code. Make it best Answer if you got help.
Visualforce Page
<apex:page controller="OppStageListCon" showHeader="false" sidebar="false" >
    <apex:form >
       <apex:pageblock >
        <apex:pageblocksection >
            <apex:outputLabel value="Select State" for="pl">
            <apex:selectList value="{!filter}" multiselect="false" size="1" id="pl">
              <apex:selectOptions value="{!Picklist}" >
                  
                </apex:selectOptions>
                <apex:actionSupport action="{!getresult}" event="onchange" reRender="p"/>
            </apex:selectList>
                </apex:outputLabel>
        </apex:pageblocksection>
           <apex:pageBlockSection id="ps">
             <apex:pageBlockTable value="{!opplist}" var="opp" id="p" >
                <apex:column value="{!opp.Name}" />
          <apex:column value="{!opp.StageName}" /> 
          <apex:column headerValue="Contact Name" >
           <apex:repeat value="{!opp.OpportunityContactRoles}" var="con">
               <apex:outputText value="{!con.Contact.Name}" />
           </apex:repeat>
          </apex:column>
               </apex:pageBlockTable>
           </apex:pageBlockSection>
       </apex:pageblock>
    </apex:form>
</apex:page>

Controller
public class OppStageListCon {
    public string filter{get;set;}
    public   List<Opportunity> opplist {get;set;}
    public list<selectoption> getPicklist(){
        list<selectoption> plist = new list<selectoption>();
        plist.add(new selectoption(' ','-None-'));
         plist.add(new selectoption('Prospecting','Prospecting'));
         plist.add(new selectoption('Qualification','Qualification'));
         plist.add(new selectoption('Needs Analysis ','Needs Analysis'));
         plist.add(new selectoption('Value Proposition','Value Proposition'));
        plist.add(new selectoption('Id. Decision Makers','Id. Decision Makers'));
          plist.add(new selectoption('Perception Analysis','Perception Analysis'));
          plist.add(new selectoption('Proposal/Price Quote','Proposal/Price Quote'));
          plist.add(new selectoption('Negotiation/Review','Negotiation/Review'));
          plist.add(new selectoption('Closed Won','Closed Won'));
          plist.add(new selectoption('Closed Lost','Closed Lost'));
        return plist;
        
    }
    public PageReference getresult(){
        system.debug('current stage'+filter);
       opplist = [SELECT Name,StageName,(SELECT ContactId,Contact.Name from OpportunityContactRoles) FROM Opportunity where StageName=:filter];
       
        return null;
        
    }

}

Regards,
Brahmaiah.​
bhanu reddy 24bhanu reddy 24
it is possible by  using one page block table and one soql query  to show all the stages (qualifiction,NeedsAnalysis) individual  tables in one vf page
bhanu reddy 24bhanu reddy 24
for example
qualification table
needsAnalysis table
one by one table will dispaly in one vf page
it is possible by using one page block table and one soql query 
bhanu reddy 24bhanu reddy 24
sry again i am asking i did not saw your msg that's y again i am asking
bhanu reddy 24bhanu reddy 24
 based on date of birth field send greeting to contact
bhanu reddy 24bhanu reddy 24
how to write a program
bhanu reddy 24bhanu reddy 24
how to put  new command link in left side search all link belowUser-added image
bhanu reddy 24bhanu reddy 24
can you plzz help me