I want to create a list of tasks, events, files and notes, so the sales man have just one list for all activities. The list works, but I still have a few questions.
I add to each list a manual field as oName which should contain the objectname. It works so far, but I can't display the oName in my list at the visual force, because I got an error --> Variable does not exist: oName , I don't know why? How can I sort the wrapperlist in the controller by createddate? is there an easy way to sort directly in the table?
public class DokuBox_5 {
public List<wrapper> wrapperList {get; set;}
public String currentRecordId {get; set;}
public DokuBox_5() {
currentRecordId = ApexPages.currentPage().getParameters().get('id');
if(wrapperList == null) {
wrapperList = new List <wrapper>();
for(Task a: [select Id, Subject, CreatedDate from Task where WhoId =: currentRecordId limit 10]) {
wrapperList.add(new wrapper(a, 'Task'));
}
for(Event b: [select Id, Subject, CreatedDate from Event where WhoId =: currentRecordId limit 10]) {
wrapperList.add(new wrapper(b, 'Event'));
}
for(ContentDocumentLink d: [SELECT Id, ContentDocumentId, ContentDocument.Title, ContentDocument.createdDate FROM ContentDocumentLink WHERE LinkedEntityId =: currentRecordId limit 10]) {
wrapperList.add(new wrapper(d, 'Note/File'));
}
}
}
public class Wrapper implements Comparable {
public Task at {get; set;}
public Event be {get; set;}
public ContentDocumentLink dc {get; set;}
public wrapper(Task a, String oName) {
at = a;
}
public wrapper(Event b, String oName) {
be = b;
}
public wrapper(ContentDocumentLink d, String oName) {
dc = d;
}
public String getSubject() {
if (at != null) return at.Subject;
else if (be != null) return be.Subject;
else if (dc != null) return dc.ContentDocument.Title;
else if (dc != null) return null;
else return '';
}
public Datetime getCreatedDate() {
if (at != null) return at.CreatedDate;
else if (be != null) return be.CreatedDate;
else if (dc != null) return dc.ContentDocument.CreatedDate;
else if (dc != null) return null;
else return null;
}
public String getId() {
if (at != null) return at.Id;
else if (be != null) return be.Id;
else if (dc != null) return dc.ContentDocumentId;
else return '';
}
public String getoName() {
if (at != null) return at.oName;
else if (be != null) return be.oName;
else if (dc != null) return dc.oName;
else return '';
}
public Integer compareTo(Object o) {
Wrapper that = (Wrapper) o;
Integer result = this.getSubject().compareTo(that.getSubject());
if (result != 0) {
return result;
} else {
if (this.getCreatedDate() > that.getCreatedDate()) return -1;
else if (this.getCreatedDate() < that.getCreatedDate()) return 1;
else return 0;
}
}
}
}
<apex:form >
<apex:pageBlock >
<apex:pageBlockTable value="{!wrapperList}" var="wl" title="all activities" styleClass="dataTable">
<apex:column headerValue="Date">
<apex:outputText value="{0,date,dd'.'MM'.'yyyy HH:mm:ss}"> <apex:param value="{!wl.createdDate}"/> </apex:outputText>
</apex:column>
<apex:column headerValue="Title" value="{!wl.subject}" />
<apex:column headervalue="LINK">
<apex:outputLink target="_blank" value="/{!wl.Id}">Details</apex:outputLink>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>