There's this error displaying every time I save the apex class: Error: Compile Error: Constructor not defined:[Checkbox_Class.oppwrapper].<Constructor>(Boolean, Opportunity)
The apex class and visualforce page below displays all contact details related to a specific searched account, as well as opportunity table row field with corresponding checkbox for each selected contact.
Controller:
public class Checkbox_Class
{
private ApexPages.StandardController controller;
public Object1__c obj1 {get;set;}
public Account accountqry {get;set;}
public List<contactwrapper> contactList {get;set;}
public List<oppwrapper> opportunityList {get;set;}
public List<Contact> selectedContacts = new List<Contact>();
public List<oppwrapper> tempWrap1 {get;set;}
public List<oppwrapper> tempWrap2 {get;set;}
public Checkbox_Class(ApexPages.StandardController con) {
controller = con;
obj1 = new Object1__c();
accountqry = new Account();
contactList = new List<contactwrapper>();
opportunityList = new List<oppwrapper>();
tempWrap1 = new List<oppwrapper>();
tempWrap2 = new List<oppwrapper>();
}
public void init() {
if(obj1.Account__c != null) {
accountqry = [SELECT Id, Name, Phone, Type FROM Account WHERE Id =: obj1.Account__c];
contactList = getContacts();
}
else {
obj1.clear();
accountqry.clear();
contactList.clear();
}
}
public List<contactwrapper> getContacts()
{
for(Contact c : [select Id, FirstName, LastName from Contact WHERE AccountId =: obj1.Account__c]) {
contactList.add(new contactwrapper(c));
}
return contactList;
}
public PageReference twoMethods() {
getSelected();
GetSelectedContacts();
createOpp();
return null;
}
public PageReference getSelected()
{
selectedContacts.clear();
for(contactwrapper conwrapper : contactList)
if(conwrapper.selected == true)
selectedContacts.add(conwrapper.con);
return null;
}
public List<Contact> GetSelectedContacts()
{
return selectedContacts;
}
public void createOpp() {
for(oppWrapper ow1 : opportunityList) {
tempWrap1.add(ow1);
}
if(selectedContacts.size() > 0) {
for(Contact con : selectedContacts) {
for(Opportunity o2 : tempWrap1) {
tempWrap2.add(new oppwrapper(false, o2));
}
}
}
}
public class contactwrapper
{
public Contact con{get; set;}
public Boolean selected {get; set;}
public contactwrapper(Contact c)
{
con = c;
selected = false;
}
}
public class oppwrapper
{
public Opportunity opp {get;set;}
public Boolean selected2 {get;set;}
public oppwrapper(Opportunity o, Boolean s)
{
opp = o;
selected2 = s;
}
}
}
Visualforce Page:
<apex:page standardController="Object1__c" extensions="Checkbox_Class">
<apex:form >
<apex:pageBlock Title="Contacts with CheckBoxes" id="tbl">
<apex:pageBlockSection title="New Object1 Record">
<apex:inputField value="{!obj1.Account__c}">
<apex:actionSupport event="onchange" action="{!init}" rerender="tbl"/>
</apex:inputField>
</apex:pageBlockSection>
<apex:pageBlockSection title="Account Information">
<apex:outputText value="{!accountqry.Name}"/>
<apex:outputText value="{!accountqry.Phone}"/>
<apex:outputText value="{!accountqry.Type}"/>
</apex:pageBlockSection>
<apex:pageBlockSection Title="List of Available Contacts">
<apex:dataTable value="{!contactList}" var="c" columnswidth="50px,50px" cellpadding="4" border="1">
<apex:column >
<apex:facet name="header"> <apex:inputCheckbox >
<apex:actionSupport event="onclick" action="{!twoMethods}" onsubmit="checkAll(this)" rerender="Selected_PBS,oppSec"/>
</apex:inputCheckbox>
</apex:facet>
<apex:inputCheckbox value="{!c.selected}" id="checkedone">
<!--<apex:actionSupport event="onclick" action="{!GetSelected}" rerender="Selected_PBS,oppSec"/></apex:inputCheckbox>-->
<apex:actionSupport event="onclick" action="{!twoMethods}" rerender="Selected_PBS,oppSec"/></apex:inputCheckbox>
</apex:column>
<apex:column headervalue="First Name" value="{!c.con.FirstName}" />
<apex:column headervalue="Last Name" value="{!c.con.LastName}" />
</apex:dataTable>
</apex:pageBlockSection>
<apex:pageBlockSection Title="Selected Contacts" id="Selected_PBS">
<apex:dataTable value="{!SelectedContacts}" var="s" columnswidth="50px,50px" cellpadding="4" border="1">
<apex:column headervalue="First Name" value="{!s.FirstName}" />
<apex:column headervalue="Last Name" value="{!s.LastName}" />
</apex:dataTable>
</apex:pageBlockSection>
<apex:pageBlockSection title="New Opportunity" columns="1">
<apex:pageBlockTable value="{!o2}" var="o">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox value="{!o.selected2}"/>
</apex:facet>
</apex:column>
<apex:column headerValue="Opportunity Name">
<apex:inputField value="{!o.opp.Name}"/>
</apex:column>
<apex:column headerValue="Amount">
<apex:inputField value="{!o.opp.Amount}"/>
</apex:column>
<apex:column headerValue="Stage">
<apex:inputField value="{!o.opp.StageName}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<script>
function checkAll(cb)
{
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++)
{
if(inputElem[i].id.indexOf("checkedone")!=-1)
inputElem[i].checked = cb.checked;
}
}
</script>
</apex:page>
Updated Controller
public class Checkbox_Class
{
private ApexPages.StandardController controller;
public Object1__c obj1 {get;set;}
public Account accountqry {get;set;}
public List<contactwrapper> contactList {get;set;}
public List<Contact> selectedContacts = new List<Contact>();
public List<oppwrapper> o2 {get;set;}
Opportunity oppNew = new Opportunity();
public Checkbox_Class(ApexPages.StandardController con) {
controller = con;
obj1 = new Object1__c();
accountqry = new Account();
contactList = new List<contactwrapper>();
}
public void init() {
if(obj1.Account__c != null) {
accountqry = [SELECT Id, Name, Phone, Type FROM Account WHERE Id =: obj1.Account__c];
contactList = getContacts();
}
else {
obj1.clear();
accountqry.clear();
contactList.clear();
}
}
public List<contactwrapper> getContacts()
{
for(Contact c : [select Id, FirstName, LastName from Contact WHERE AccountId =: obj1.Account__c]) {
contactList.add(new contactwrapper(c));
}
return contactList;
}
public PageReference twoMethods() {
getSelected();
GetSelectedContacts();
createOpp();
return null;
}
public PageReference getSelected()
{
selectedContacts.clear();
for(contactwrapper conwrapper : contactList)
if(conwrapper.selected == true)
selectedContacts.add(conwrapper.con);
return null;
}
public List<Contact> GetSelectedContacts()
{
return selectedContacts;
}
public void createOpp() {
List<oppwrapper> o2 = new List<oppwrapper>();
if(selectedContacts.size() > 0) {
for(Contact con : selectedContacts) {
o2.add(new oppwrapper(oppNew,false));
}
}
}
public class contactwrapper
{
public Contact con{get; set;}
public Boolean selected {get; set;}
public contactwrapper(Contact c)
{
con = c;
selected = false;
}
}
public class oppwrapper
{
public Opportunity opp {get;set;}
public Boolean selected2 {get;set;}
public oppwrapper(Opportunity o, Boolean s)
{
opp = o;
selected2 = s;
}
}
}