+ Start a Discussion
RAAMRAAM 

Need help adding a few contacts displayed using apex:enhancedList into my custom junction object.

I have created a MailList custom object similar to Campaign object and a MailList History junction object. Now i need to create a wizard to mass add contacts into my MailList History junction object. I already created the first page of my wizard to select the MailList Name and Status and in the second page select a few contacts displayed using the enhancedlist ie "<apex:enhancedList type="Contact" customizable="true" height="300" rowsPerPage="10" id="AccountList"></apex:enhancedList>". Now my question is how add the selected contacts into my junction object MailList History, Plz provide a code sample i have pasted my code sample below Plz help me ....

visualforce page1:-



visualforce page1 code:-

<apex:page standardController="Contact" extensions="customController5">
<apex:sectionHeader title="Select MailList"
subtitle="Step 1 of 2"/>
<apex:form >
<apex:pageBlock title="MailList Information">
<apex:pageBlockSection >
<apex:panelGrid columns="2">
<apex:outputLabel value="MailListName" for="maillistname">
</apex:outputLabel>
<apex:inputField id="maillistname" value="{!mailhistory.MailList_Name__c}" required="true">
</apex:inputField>
<apex:outputLabel value="Status" for="status">
</apex:outputLabel>
<apex:inputField id="status" value="{!mailhistory.Status__c}" required="true">
</apex:inputField>
</apex:panelGrid>
</apex:pageBlockSection>
<apex:pageBlockButtons location="both">
<apex:commandButton value="Next" action="{!step2}">
</apex:commandButton>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>

visualforce page2:-



visualforce page2 code:-

<apex:page standardController="Contact" extensions="customController5">
<apex:enhancedList type="Contact" customizable="true" height="300" rowsPerPage="10" id="AccountList">
</apex:enhancedList>
<apex:pageBlock >
<apex:form >
<apex:commandButton value="Add to MailList">
</apex:commandButton>
</apex:form>
</apex:pageBlock>
</apex:page>

Controller code:-

public class customController5
{
    private final Contact cont;
   
    public string contTypeID {get; set;}
   
    public customController5(ApexPages.StandardController
           contController)
           {
               this.cont = (Contact)contController.getRecord();
           }
    Contact contact;
    MailList__c maillist;
    MailList_History__c mailhistory;
     
   public Contact getContact()
   {
    if(contact == null)
    contact = new Contact();
    return contact;
   }
  
    public MailList__c getMaillist()
   {
    if(maillist == null)
    maillist = new MailList__c();
    return maillist;
   }
  
   public MailList_History__c getMailhistory()
   {
       if(mailhistory == null)
       mailhistory = new MailList_History__c();
       return mailhistory;
   }
  
   
            
    public PageReference step1()
   {
       return Page.Wizard1;
   }
  
   public PageReference step2()
   {
       return Page.Example;
   }
  
  public PageReference save()
  {
     
     // code to add  selected contacts to maillist history junction object should come here
      return Page.Example;
  }
}













Message Edited by RAAM on 12-16-2008 09:57 PM
jwetzlerjwetzler

This would be a good use of the Standard List Controller that is documented here.

 

I think the best solution for you is to create a custom list button on your contact list that refers to your Visualforce page (your visualforce page must leverage the standard list controller in order to be available as a target for a custom list button -- your extension can provide all of the custom logic you need).  The selections you make inside of your enhanced list will be passed as the record set when you click on your custom list button. 

MiliMili

hey

did you get this issue resolved?

Can you please  share the code if this is resolved?(code to get selected contacts from the listview)