You need to sign in to do that
Don't have an account?
Sreeram Chakrapani
Display Records from a Custom Object tied to a Opportunity
Hi Folks,
I have a custom object that is related to the opportunity object through a master detail relationship. On the click of a button which is on a Visual Force Page, i would like to open up another Visual Force Page and display all the records from the custom object related to the opportunity, can somebody help me out with starter code for this ? Appreciate the help
Thanks
Sree
I have a custom object that is related to the opportunity object through a master detail relationship. On the click of a button which is on a Visual Force Page, i would like to open up another Visual Force Page and display all the records from the custom object related to the opportunity, can somebody help me out with starter code for this ? Appreciate the help
Thanks
Sree
Then your second page would use the Opportunity as a Standard Controller, along with an apex class for your Extension. For more on Standard Controllers and Extensions, see here: http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm
In general, your second page, which displays the related values, would look like:
Your apex extension class might look like the following:
All Answers
Then your second page would use the Opportunity as a Standard Controller, along with an apex class for your Extension. For more on Standard Controllers and Extensions, see here: http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm
In general, your second page, which displays the related values, would look like:
Your apex extension class might look like the following:
Use the following code for your requirement.
First Page:
***********
<apex:page controller="SampleController">
<apex:form >
<apex:commandButton value="redirectPage"/>
</apex:form>
</apex:page>
First Controller:
*****************
public class SampleController {
public Opportunity opp = new Opportunity();
public SampleController(){
opp = [SELECT Id FROM Opportunity Limit 1];//include your logic to select the opportunity record.
}
public pagereference redirectPage(){
pagereference ref = new pagereference('/apex/NewPage?id='+opp.Id);
ref.setRedirect(true);
return ref;
}
}
Second Page:
*******************
<apex:page controller="Newcontroller123">
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!cLst}" var="c">
<apex:column value="{!o.id}"/>
<apex:column value="{!o.name}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Second Controller:
**********************
public class Newcontroller123 {
public Opportunity[] cLst { get; set; }
public Newcontroller123(){
cLst = new Opportunity[]{};
cLst = [SELECT Id,name from Custom_Object__c WHERE Opportunity__c =: apexpages.currentpage().getparameters().get('id')];
//Opportunity__c is the reference field for the Opportunity obj on the Custom Object.
}
}
Dont forget to like
Thanks,
Vijay