You need to sign in to do that
Don't have an account?
RAAM
Need help building a wizard similar to the mass add contacts to campaign wizard.
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...
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...
Please see
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=756
good luck
private Contact theContact;
private boolean selected = false;
public ContactSelect(Contact a) {
theContact= a;
}
public Contact getTheContact() {
return theContact;
}
public void setTheContact(Contact a) {
theContact = a;
}
public boolean getSelected() {
return selected;
}
public void setSelected(boolean b) {
this.selected = b;
}
}
contacts = new List<ContactSelect>();
Contact[] original_contacts = [select Id, Name, ......... from Contac where ......];
for(Contact a:original_contacts ) {
ContactSelect cs = new ContactSelect(a);
contacts.add(cs);
}
return contacts ;
}
Your_Junction_Object[] JOs = new Your_Junction_Object[]{};
System.StringException: Invalid id: Stella Pavlova
Class.customController2.save: line 119, column 77
External entry point
This is my apex 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;
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;
}
List<mContact> contacts = new List<mContact>();
public List<mContact> getContacts ()
{
contacts = new List<mContact>();
Contact[] original_contacts = [select 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()
{
MailList_History__c [] mh = new MailList_History__c []{};
for(mContact c: contacts )
{
if(c.getSelected())
{Contact con = c.getContact();
MailList_History__c m = new MailList_History__c(Contact__c=con.name);
mh.add(m);
}
}
insert mh;
return Page.Wizard2;
}
}
Plz help...
Message Edited by RAAM on 12-08-2008 06:47 AM
-- correct expression should like
{
MailList_History__c [] mh = new MailList_History__c []{};
for(mContact c: contacts )
{
if(c.getSelected())
{Contact con = c.getContact();
MailList_History__c m = new MailList_History__c(Contact__c=con.name);
mh.add(m);
}
}
insert mh;
return Page.Wizard2;
}
Message Edited by RAAM on 12-08-2008 04:23 PM
Message Edited by RAAM on 12-08-2008 05:39 PM
Message Edited by RAAM on 12-08-2008 05:40 PM
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;
}
}
Message Edited by RAAM on 12-10-2008 05:31 AM
two ways
MailList_History__c is juction object?
1. you can create custom field on contact- checkbox. First time you select it and insert it into junction object, you set that True (mass update contact via list or array)
Next time you check each contact you selected in save() .if (selected and checkbox_field != true ) add into m array. finally insert the array with contact selected and not in your junction object.
2. in your save(), you can do query first to get all records in your junction object into a Map. Using Map method "containsKey" to test whether or not your selected contacts in the map. If yes, that mean duplicate. You don't need to add them into m array.
public class customController4
{
public class mhistory
{
MailList_History__c mhis;
boolean selected=false;
public mhistory(MailList_History__c mcon)
{
mhis=mcon;
}
public MailList_History__c getMailList_History()
{
return mhis;
}
public void setMailList_History(MailList_History__c mcon)
{
mhis=mcon;
}
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[]{};
//MailList__c mid = [select Name from MailList__c where id = : System.currentPageReference().getParameters().get('id')];
String query = System.currentPageReference().getParameters().get('q');
public string getQuery()
{
return query;
}
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;
}
//mHistory [] historys;
// String mname = mailhistory.MailList_Name__c;
List<mHistory> historys = new List<mHistory>();
//MailList_History__c [] mh = [select id,contact__c,MailList_Name__c from MailList_History__c];
public List<mHistory> getHistorys ()
{
historys = new List<mHistory>();
MailList_History__c[] original_historys;
original_historys = [select Id, Contact__c, MailList_Name__c, Status__c from MailList_History__c];
for(MailList_History__c a : original_historys)
{
mHistory ms = new mHistory(a);
historys.add(ms);
}
return historys ;
}
/* public List<MailList_History__c> getMstatus()
{
mstatus = new List<MailList_History__c>();
original_mstatus = [select Id,status__c from MailList_History__c];
*/
public PageReference step1()
{
return Page.Wizard1;
}
public PageReference step2()
{
return Page.Wizard4;
}
/* 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;
}*/
}
<apex:page controller="customController4" tabstyle="MailList__c">
<apex:sectionHeader title="Select Contacts To Add"
subtitle="Step 2 of 2"/>
<apex:panelGrid columns="1" id="theGrid" width="100%">
<apex:form >
<apex:pageBlock >
<apex:dataTable value="{!Historys}" var="mcon" styleClass="list">
<apex:column >
<apex:facet name="header">CheckBox
</apex:facet>
<apex:inputCheckbox value="{!mcon.selected}" />
</apex:column>
<apex:column >
<apex:facet name="header">Contact Name</apex:facet>
<apex:outputText value="{!mcon.MailList_History.Contact__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">MailList Name</apex:facet>
<apex:outputText value="{!mcon.MailList_History.MailList_Name__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Status</apex:facet>
<apex:outputText value="{!mcon.MailList_History.Status__c}"/>
</apex:column>
</apex:dataTable>
<apex:pageblockButtons location="both">
<apex:commandButton Value="Previous">
</apex:commandButton>
<apex:commandButton value="Add Selected Contacts">
</apex:commandButton>
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form>
</apex:panelGrid>
</apex:page>
Message Edited by RAAM on 12-12-2008 03:07 AM
Message Edited by RAAM on 12-12-2008 10:25 AM
{
historys = new List<mHistory>();
MailList_History__c[] original_historys;
original_historys = [select Id, Contact__c, Contact__r.Name, MailList_Name__c,MailList_Name__r.Name, Status__c from MailList_History__c];
for(MailList_History__c a : original_historys)
{
mHistory ms = new mHistory(a);
historys.add(ms);
}
return historys ;
}
Contact__r.Name--- to get contact name
<apex:facet name="header">Contact Name</apex:facet>
<apexutputText value="{!mcon.MailList_History.Contact__r.Name}"/>
</apex:column>
VF page1 code:-
<apex:page controller="customController4" tabstyle="MailList__c">
<apex:sectionHeader title="Update Members Status From a List of Contacts"
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:outputText style="font-style:bold" value="{!query}">
</apex:outputText>
<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:param name="q2" value="{!Mailhistory.Status__c}">
</apex:param>
</apex:commandButton>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
VF page1 image:-
VF page 2 code:-
<apex:page controller="customController4" tabstyle="MailList__c">
<apex:sectionHeader title="Select Contacts To Add"
subtitle="Step 2 of 2"/>
<apex:panelGrid columns="1" id="theGrid" width="100%">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:outputLabel value="Update Status to... : " for="theStatus">
</apex:outputLabel>
<apex:outputText id="theStatus" value="{!query2}">
</apex:outputText>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:dataTable value="{!Historys}" var="mcon" styleClass="list">
<apex:column >
<apex:facet name="header">CheckBox
</apex:facet>
<apex:inputCheckbox value="{!mcon.selected}" />
</apex:column>
<apex:column >
<apex:facet name="header">Contact Name</apex:facet>
<apex:outputText value="{!mcon.MailList_History.Contact__r.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">MailList Name</apex:facet>
<apex:outputText value="{!mcon.MailList_History.MailList_Name__r.Name}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Status</apex:facet>
<apex:outputText value="{!mcon.MailList_History.Status__c}"/>
</apex:column>
</apex:dataTable>
<apex:pageblockButtons location="both">
<apex:commandButton Value="Previous">
</apex:commandButton>
<apex:commandButton value="Update Selected Contacts">
</apex:commandButton>
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form>
</apex:panelGrid>
</apex:page>
VF page2 image:-
Controller code:-
public class customController4
{
public class mhistory
{
MailList_History__c mhis;
boolean selected=false;
public mhistory(MailList_History__c mcon)
{
mhis=mcon;
}
public MailList_History__c getMailList_History()
{
return mhis;
}
public void setMailList_History(MailList_History__c mcon)
{
mhis=mcon;
}
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[]{};
//MailList__c mid = [select Name from MailList__c where id = : System.currentPageReference().getParameters().get('id')];
String query = System.currentPageReference().getParameters().get('q');
String query2 = System.currentPageReference().getParameters().get('q2');
public string getQuery()
{
return query;
}
public string getQuery2()
{
return query2;
}
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;
}
//mHistory [] historys;
// String mname = mailhistory.MailList_Name__c;
List<mHistory> historys = new List<mHistory>();
//MailList_History__c [] mh = [select id,contact__c,MailList_Name__c from MailList_History__c];
public List<mHistory> getHistorys ()
{
historys = new List<mHistory>();
MailList_History__c[] original_historys;
original_historys = [select Id, Contact__c, Contact__r.Name, MailList_Name__r.Name, Status__c from MailList_History__c where MailList_Name__r.Name = :query];
for(MailList_History__c a : original_historys)
{
mHistory ms = new mHistory(a);
historys.add(ms);
}
return historys ;
}
/* public List<MailList_History__c> getMstatus()
{
mstatus = new List<MailList_History__c>();
original_mstatus = [select Id,status__c from MailList_History__c];
*/
public PageReference step1()
{
return Page.Wizard3;
}
public PageReference step2()
{
return Page.Wizard4;
}
public PageReference save()
{
for(mHistory m: historys )
{
if(m.getSelected())
{MailList_History__c mcon = m.getMailList_History();
// ID mconid=mcon.ID;
// MailList_History__c mh = [select status__c from MailList_History__c];
mcon.Status__c = mailhistory.Status__c;
update mcon;
//i++;
}
}
return Page.Wizard2;
}
}
Also plz help me with this topic
Message Edited by RAAM on 12-16-2008 02:55 AM
if you see my previous post and understand the purpose that I added status variable.
public PageReference save()
{
MailList_History__c[] ms = new MailList_History__c[]{};
for(mHistory m: historys )
{
if(m.getSelected())
{ MailList_History__c mcon = m.getMailList_History();
mcon.Status__c = status;
ms.add(mcon);
}
}
update ms;
return Page.Wizard2;
}
Link:-
http://community.salesforce.com/sforce/board/message?board.id=Visualforce&thread.id=7717
Message Edited by RAAM on 12-16-2008 08:26 PM
Message Edited by RAAM on 12-16-2008 10:15 PM