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
Akanksha sharma 15Akanksha sharma 15 

there is look up relationship between opportunity and case i need to find soql qery to find all related case for opportunity

there is look up relationship between opportunity and case i need to find soql qery to find all related case for opportunity here is my query please anyone help where i am wrong

 
<apex:page standardController="Opportunity" extensions="stucasecontroller1">
   <apex:form >
   <apex:pageBlock title="relatedlist details">
   
   <apex:pageblockSection title="case realted list ">
   <apex:pageBlocktable value="{!cas}" var="c" >
   
   <apex:column value="{!c.status}"/>
   <apex:column value="{!c.origin}"/>
   </apex:pageblocktable>
   </apex:pageblockSection>
   
   </apex:pageBlock>
   
  </apex:form>
</apex:page>


 public class stucasecontroller1 {

public string oppID{get;set;}
public List<case> caslist{get;set;}


    public stucasecontroller1 (){
       cas=[select Id,status,origin,opportunity__r.Name,opportunity__c  from case where opportunity__c=:oppID];

    }


   


    

}
Best Answer chosen by Akanksha sharma 15
sfdcMonkey.comsfdcMonkey.com
Hi Akashnsha , use folloing apex class :
public class stucasecontroller1 {
    public List<case> cas{get;set;}
   
    public stucasecontroller1 (ApexPages.StandardController controller){
        cas = [select Id,status,origin,opportunity__r.Name,opportunity__c  from case
               where opportunity__c =: ApexPages.currentPage().getParameters().get('id')];
    } 
}

Next add your vf page to Opportunity page layout so it can take current opportunity id to query all realted calse :
edit opportunity page layout and drag your vf page to opportunity detail page :
User-added image

output :
User-added image

Thanks, let us know if it helps you, and if it solved your issue kindly close this query with best answer so it will helps others in future

All Answers

sfdcMonkey.comsfdcMonkey.com
Hi Akashnsha , use folloing apex class :
public class stucasecontroller1 {
    public List<case> cas{get;set;}
   
    public stucasecontroller1 (ApexPages.StandardController controller){
        cas = [select Id,status,origin,opportunity__r.Name,opportunity__c  from case
               where opportunity__c =: ApexPages.currentPage().getParameters().get('id')];
    } 
}

Next add your vf page to Opportunity page layout so it can take current opportunity id to query all realted calse :
edit opportunity page layout and drag your vf page to opportunity detail page :
User-added image

output :
User-added image

Thanks, let us know if it helps you, and if it solved your issue kindly close this query with best answer so it will helps others in future
This was selected as the best answer
Akanksha sharma 15Akanksha sharma 15
hi piyush,
I used this but with this page i am getting list of all related case but what i want related case for particular opportunity.my scenario is i have one clone case button on standard page of opportuntiy when i click on this button i will get related cases of that opportunity .but i am getting all the cases that is related to all the opportunity.Please help me out
sfdcMonkey.comsfdcMonkey.com
yes, above code will fetch only case which are related to particular (open) opportunity,
create a custom detail page clone button which is open your VF page,