function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vegaln1Vegaln1 

Recieving 'Contstructor Not Defined Error' on sample APEX.

Hello.. I've found  a sample piece of APEX code that would addresses a requirement we have,  however I receive this error when compiling the CaseHistoryCon.cls:

 

Save error: Constructor not defined: [History].<Constructor>(Datetime, Boolean, String, String, String, String, String)    CaseHistoryCon.cls    line 58   

 

 

Any suggestions on how to correct this? I've included the CaseHistoryCon.cls and the History.cls. It appears we're sending the correct number of parameters. This would seem pretty straignt forward but so far the fix has eluded me.

 

Regards,

public class CaseHistoryCon {
public boolean fullComments { get; private set; }
// Property value that controls visibility of related objects which are not visible in the customer portal.
public boolean hidePrivate { get; private set; }
private final Case ca;
public CaseHistoryCon(ApexPages.StandardController controller) {
this.ca = (Case)controller.getRecord();
fullComments = true;
hidePrivate = true;
truncatedCommentLength = 100;
cid = ca.id;
}
// Action method for toggling the fullComments property
public void toggleComments() { fullcomments = !fullcomments; }

// Action method for toggling the visibility control for private related objects.
public void togglePrivate() { hidePrivate = !hidePrivate; }

// Action method for navigating the user back to the case page.
public PageReference backToCase() {
return new ApexPages.StandardController(c).view();
}

// Accessor for retrieving the case object and its related items. If the cid property is null this
// method will return a new, empty case object. The functionality in this method could have been placed
// in the get property accessor for the private property named 'c' below but for simplicity of the page
// author in referencing the current case object this method was created because it is not possible to
// create a variable named 'case' since it is a reserved term in Apex.
public Case getcase() {

if(cid == null) return new Case();
return [SELECT casenumber, subject, contact.name, contact.email,
(SELECT CreatedBy.Name, CreatedDate, CommentBody,IsPublished FROM CaseComments ORDER BY CreatedDate ASC),
(SELECT CreatedBy.Name, CreatedDate, Field, NewValue, OldValue FROM Histories ORDER BY CreatedDate ASC),
(SELECT CreatedBy.Name, CreatedDate, Name FROM Attachments ORDER BY CreatedDate ASC),
(SELECT Owner.Name, ActivityDateTime, Subject, IsVisibleInSelfService FROM Events WHERE ActivityDateTime <= :System.Now() ORDER BY ActivityDateTime ASC),
(SELECT Owner.Name, LastModifiedDate, Subject, IsVisibleInSelfService, Description FROM Tasks WHERE ActivityDate <= :System.Today() // added Description THS 8/2009
AND IsClosed = true ORDER BY LastModifiedDate ASC)
FROM case
WHERE id = :cid];

}

// This accessor provides the page with the ordered collection of history (apex) objects for display in the page.
// it also processes the truncation of case comments as specified by the fullComments property value.
public History[] getHistories() {
History[] histories = new History[]{};
for (CaseComment comment:c.casecomments) {
if (!hidePrivate || comment.ispublished) {
addHistory(histories, new History(comment.createdDate, comment.ispublished, comment.createdby.name,'' ,'Comment Added', '' , truncateValue(comment.commentbody)));
}
}

for (Event e:c.events) {
if (!hidePrivate || e.isvisibleinselfservice) {
addHistory(histories, new History(e.activitydatetime, e.isvisibleinselfservice, e.owner.name, '' , 'Event Completed', '' , e.subject));
}
}

for (Task t:c.tasks) {
if (!hidePrivate || t.isvisibleinselfservice) {
addHistory(histories, new history(t.lastmodifieddate, t.isvisibleinselfservice, t.owner.name, t.Subject , 'Task Completed', '' , t.Description)); //Added Description THS 8/2009 subject
}
}
for (CaseHistory ch:c.histories) {
addHistory(histories, new history(ch.createdDate, true, ch.createdby.name, ch.field + ' Change', String.valueOf(ch.oldvalue), String.valueOf(ch.newvalue)));
system.debug('##################### CaseHistory: ' +ch.oldvalue + ' ' +ch.newvalue);
}

for (Attachment a:c.attachments) {
addHistory(histories, new history(a.createdDate, true, a.createdby.name,'' , 'Attachment Added', '' , a.name));
}

return histories;
}

// This method adds the newHistory object to the given histories collection in the appropriate order.
// The order provided here places the oldest records at the front of the list, i.e. by date ascending.
private void addHistory(History[] histories, History newHistory) {
Integer position = histories.size();
for (Integer i = 0; i < histories.size(); i++) {
if (newHistory.historydt < histories[i].historydt) {
position = i;
break;
}
}

if (position == histories.size()) {
histories.add(newHistory);
} else {
histories.add(position, newHistory);
}
}

// Returns the truncated string value if that is specified in the current state (!fullComments)
// and the current length is greater than the value of the private truncatedCommentLength property.
private String truncateValue(String s) {
if (!fullComments && s.length() > truncatedCommentLength) {
s = s.substring(0,truncatedCommentLength) + '...';
}

return s;
}

// The ID value of the case that will be used by the getCase() method to query for the related
// objects used to generate the ordered history collection. The value will be based on the request
// parameter, if available.
private Id cid {
get {
if(ApexPages.currentPage().getparameters().get('cid') != null) {
cid = ApexPages.currentPage().getparameters().get('cid');
}
return cid;
}
set {
if(value != null) cid = value;
}
}

// The case object set by the getCase method and used by the getHistories method to acquire
// the related records.
private Case c {
get { return getCase(); }
set;
}

// The length of "Short Comments" which is used by the truncateValue method in this class to
// truncate case comments when specified by the user.
private Integer truncatedCommentLength { get; set; }

public PageReference NavigateToPrintablePage() {
//cid = ApexPages.currentPage().getparameters().get('cid');
PageReference pageRef = new PageReference('/apex/caseHistoryPrint');
if(ApexPages.currentPage().getparameters().get('cid') != null) {
cid = ApexPages.currentPage().getparameters().get('cid');
}
return pageRef;

}

}

 

 

public class History{ // Properties of the class. Changed from history to History to avoid compile errors in other classes/pages. public datetime historydt { get; private set; } public boolean ispublic { get; private set; } public string actorname { get; private set; } public string historyType { get; private set; } public string to { get; private set; } public string fr { get; private set; } // Class constructor public History(Datetime d, boolean p, String actor, String ht, String f, String t) { historydt = d; historydate = d.format(); ispublic = p; actorname = actor; historyType = ht; fr = f; to = t; } // Formatting methods utilized primarily by the CaseHistoryPrint Visualforce page public string historydate { get; set; } public string dtmonthyr { get { return historydt.format('MMMMM yyyy'); } } public string dttime { get { return historydt.format('h:mm a');} } public string dtdayfmt { get { return historydt.format('d - EEEE'); } } public integer dtmonth { get { return historydt.month();} } public integer dtyear { get { return historydt.year();} } public integer dtday { get { return historydt.day();} } }

 


 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Vegaln1Vegaln1
I think this issue is because the CaseHistoryCon.cls is using the Standard Controller and actually the CaseHistoryCon should be called as a custom Controller. The History() would need to be called within the CaseHistoryCon.cls if it is to be used as custom extension.

All Answers

Vegaln1Vegaln1
I think this issue is because the CaseHistoryCon.cls is using the Standard Controller and actually the CaseHistoryCon should be called as a custom Controller. The History() would need to be called within the CaseHistoryCon.cls if it is to be used as custom extension.
This was selected as the best answer
JimRaeJimRae

The problem is that your History constructor takes 6 parameters, and you are passing 7.

 

History is expecting this: 

 

Datetime d, boolean p, String actor, String ht, String f, String t

 

 But you are passing this:

 

 

comment.createdDate, comment.ispublished, comment.createdby.name,'' ,'Comment Added', '' , truncateValue(comment.commentbody)

 

 

 

 

 

 

 

Vegaln1Vegaln1

Hello JimRae.. Thank you for the suggestion. Even if I remove the last parameter I still recieve the same message. If I make the  class a custom controller, it seems to work fine with no changes.

 

Regards,