You need to sign in to do that
Don't have an account?

Constructor not defined: error when I try to add values to a wrapper class
I am trying to write a class to create a combined list of events and tasks in descending order of created dates. I need to limit the list to the last 50 records. I am using a for loop to compare the created dates of tasks and events then trying to assign the record the wrapper class to get the correct order. When I try to assign the task or activity I get an error that states. "undefinedConstructor not defined: [CTRL_MCContacActivities.activityWrapper].(Event)undefined" and "undefinedConstructor not defined: [CTRL_MCContacActivities.activityWrapper].(Task)undefined". I have found mulitple examples and have not been able to find out what is wrong. My code is below.
public with sharing class CTRL_MCContactActivities {
private Contact theContact;
public Map<String, String> params {get;set;}
public Integer getRetailActivitesCount {get;set;}
public String conId;
public List<Activity_Contact__c> activities {set;get;}
Public List<Task> taskList {get; set;}
Public List<Event> eventList {get; set;}
Public integer tc = 0;
Public integer ec = 0;
public List<activityWrapper> activityList {get; set;}
public CTRL_MCContactActivities(ApexPages.StandardController controller) {
theContact = (Contact) controller.getRecord();
If (theContact != null) {
activityList = new List<activityWrapper>();
taskList = [SELECT Id, Activity_Type__c, CreatedDate, Meeting_Type__c, Subject, ActivityDate, Description, Activity_Status__c, Owner.Name
FROM task
WHERE Id IN (Select taskId from taskRelation where Relationid = :theContact.Id) order by CreatedDate DESC] ;
eventList = [SELECT Id, Activity_Type__c, CreatedDate, Meeting_Type__c, Subject, ActivityDate, Description,Activity_Status__c, Owner.Name
FROM event
WHERE Id IN (Select eventId from eventRelation where Relationid = :theContact.Id) order by CreatedDate DESC] ;
IF(taskList.size() > 0 && eventList.size() > 0){
FOR(integer i = 0; i < 50; i++){
system.debug(i+' ***** task CreatedDate '+taskList[tc].CreatedDate+' event CreatedDate '+eventList[ec].CreatedDate);
IF(taskList[tc].CreatedDate > eventList[ec].CreatedDate){
activityList.add(new activityWrapper(taskList[tc]));
tc++;
}else{
activityList.add(new activityWrapper(eventList[ec]));
ec++;
}
}
}
}
//Wrapper Class
public class activityWrapper{
Task t {get; set;}
Event e {get; set;}
}
public with sharing class CTRL_MCContactActivities {
private Contact theContact;
public Map<String, String> params {get;set;}
public Integer getRetailActivitesCount {get;set;}
public String conId;
public List<Activity_Contact__c> activities {set;get;}
Public List<Task> taskList {get; set;}
Public List<Event> eventList {get; set;}
Public integer tc = 0;
Public integer ec = 0;
public List<activityWrapper> activityList {get; set;}
public CTRL_MCContactActivities(ApexPages.StandardController controller) {
theContact = (Contact) controller.getRecord();
If (theContact != null) {
activityList = new List<activityWrapper>();
taskList = [SELECT Id, Activity_Type__c, CreatedDate, Meeting_Type__c, Subject, ActivityDate, Description, Activity_Status__c, Owner.Name
FROM task
WHERE Id IN (Select taskId from taskRelation where Relationid = :theContact.Id) order by CreatedDate DESC] ;
eventList = [SELECT Id, Activity_Type__c, CreatedDate, Meeting_Type__c, Subject, ActivityDate, Description,Activity_Status__c, Owner.Name
FROM event
WHERE Id IN (Select eventId from eventRelation where Relationid = :theContact.Id) order by CreatedDate DESC] ;
IF(taskList.size() > 0 && eventList.size() > 0){
FOR(integer i = 0; i < 50; i++){
system.debug(i+' ***** task CreatedDate '+taskList[tc].CreatedDate+' event CreatedDate '+eventList[ec].CreatedDate);
IF(taskList[tc].CreatedDate > eventList[ec].CreatedDate){
activityList.add(new activityWrapper(taskList[tc]));
tc++;
}else{
activityList.add(new activityWrapper(eventList[ec]));
ec++;
}
}
}
}
//Wrapper Class
public class activityWrapper{
Task t {get; set;}
Event e {get; set;}
}
Ref: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_constructors.htm
All Answers
Ref: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_constructors.htm
wil,