• RAAM
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 11
    Replies
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
  • December 16, 2008
  • Like
  • 0
 i select a few contacts and mass add them to my junction object,how to prevent from adding dulicates values ie contacts into my junction object??

this is my final working code

public class customController2
{

    public class mcontact
    {
        contact c;
        boolean selected=false;
       
        public mcontact( contact con)
        {
            c=con;
        }
      
        public Contact getContact()
        {
            return c;
        }
       
        public void setContact(Contact con)
        {
            c=con;
        }
           
        public boolean getSelected()
        {
          return selected;
        }
     
      public void setSelected(boolean sb)
      {
          this.selected = sb;
      }
    }
   
    Contact contact;
    MailList__c maillist;
    MailList_History__c mailhistory;
   // Integer i;
    String[] conts = new String[]{};
   
   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;
   }
  
   //mContact [] Contacts;
   List<mContact> contacts = new  List<mContact>();
   //MailList_History__c [] mh = [select id,contact__c,MailList_Name__c from MailList_History__c];
   
    public List<mContact> getContacts ()
    {
         
            contacts = new List<mContact>();
            Contact[] original_contacts;
         
            original_contacts = [select Id, Name, Phone, MailingCity, Email from Contact];
     
            for(Contact a : original_contacts)
            {
                mContact cs = new mContact(a);
                contacts.add(cs);                 
            }
           
        return contacts ;
    }
        
    public PageReference step1()
   {
       return Page.Wizard1;
   }
  
   public PageReference step2()
   {
       return Page.Wizard2;
   }
  
  public PageReference save()
  {
          for(mContact c: contacts )
      {
             if(c.getSelected())
             {Contact con = c.getContact();
            
                 ID conid=con.ID;
                 MailList_History__c m = new 
MailList_History__c(Contact__c=conid,MailList_Name__c=mailhistory.MailList_Name__c,Status__c=mailhistory.Status__c);
                 insert m;
                 //i++;           
             }
      }
    
      return Page.Wizard2;
  }
}

  • December 10, 2008
  • Like
  • 0
I have a Picklist called Status in my junction object visualforce page, it contains three values. I need to display to the values in another visualforce page in a table and i also need to add additional values to the picklist, how do i do it plz help me...
  • December 10, 2008
  • Like
  • 0
I have built a custom object similar to campaign say "A" and also built a junction object which links object A and contacts. Next i built a two page wizard to mass add selected contacts into the junction object. In the first page of wizard i select the name and status and in the second page i need to display a list of contacts with their name and a checkbox. So when i select a few checkboxes to choose contacts and click a button to add those contacts into my junction object.

I need a sample code of how to display a list of contacts with checkboxes and sample code of how to add the selected contacts into the juction object. Plz help me...
  • December 07, 2008
  • Like
  • 0
I have built a custom object similar to campaign say "A" and also built a junction object which links object A and contacts. Next i built a two page wizard to mass add selected contacts into the junction object. In the first page of wizard i select the name and status and in the second page i need to display a list of contacts with their name and a checkbox. So when i select a few checkboxes to choose contacts and click a button to add those contacts into my junction object.

I need a sample code of how to display a list of contacts with checkboxes and sample code of how to add the selected contacts into the juction object. Plz help me...
  • December 07, 2008
  • Like
  • 0