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

Related Lists / Visualforce Apex Classes / Listing newbish syntax

I am trying to figure out how to link a Master/Detail object and a lookup related object in the apex code.


my goals is that i have packages and products. in products, i want to be able to put them into packages if i want to and discount the packages.


in the apex class, how do i start coding this? i am operating from the perspective of the package. from the package i want to populate a multi-select / array of check boxes with all the opportunity products that meet specific parameters (A SOQL SELECT STATEMENT).


i want to be able to add or delete objects from this package, the trick is that this package is linked to the products (That populates opportunity products) via a many:many link using another table.. any ideas?



current visualforce page:

<apex:page standardController="Packages__c" extensions="productpackageextensions">
      <!--  <apex:relatedList list="OpportunityLineItems"/> -->
       <!-- <apex:relatedList list="ProductPackage__c"/> -->
 <apex:form >

   <apex:pageBlock title="Let's add Products to Packages {!$User.FirstName}">
    <apex:pageMessages />
    <apex:pageBlockButtons >
    <apex:commandButton value="Save" action="{!save}"/>
    <apex:commandButton value="Cancel" action="{!cancel}"/>
      <h1>Click Save to Add</h1>
      <apex:pageBlockSection >
       <apex:outputField value="{!}"/> 

     <!--  <apex:inputField value="{!Packages__c.ProductPackage__c.Product2}"/> -->
      <!-- End Default Content REMOVE THIS -->

 current apex class code:

public class productpackageextensions{
private final Packages__c packageObj;
public productpackageextensions(ApexPages.StandardController controller) {
this.packageObj = (Packages__c)controller.getSubject();

public Packages__c[] getPackageProducts() {




The visualforce developer's guide has an example of programmatically creating a multi-select style component.  Its around selecting field, but it boils down to a lists of strings (that could be ids) and moving them between available and selected components.  That should give you a start in terms of the selection process:|StartTopic=Content%2Fpages_dynamic_vf.htm|SkinName=webhelp


Many to many is simply a junction object in Salesforce parlance - essentially its a record with two masters.  In this case one would be the package and the other the product.