You need to sign in to do that
Don't have an account?
Jonathan Wolff 7
Rewrite apex class to combine results of task and event
Hi I build a wrapper class so i can combine results from events and tasks into one list. the problem i have is, that i think i need to split the list in smaller details. Could you show me how to change my apex class so i can use the fields together within one list.
My current class is like that:
But i think the working apex class should have this form but i dont know how i can achive it:
My current class is like that:
public class ApexActivityWrapper { @AuraEnabled public static wrapper method1 (){ string userId = UserInfo.getUserId(); List<Task> getTask = [SELECT Subject, ActivityDate FROM Task WHERE OwnerId=:userId ORDER BY ActivityDate Limit 20]; List<Event> getEvent = [SELECT Subject, ActivityDate FROM Event WHERE OwnerId=:userId ORDER BY ActivityDate Limit 20]; wrapper wrp = new wrapper(); wrp.taskList = new List<Task>(getTask); wrp.eventList = new List<Event>(getEvent); return wrp; } public class wrapper{ @AuraEnabled public List<Task> taskList ; @AuraEnabled public List <Event> eventList; } }
But i think the working apex class should have this form but i dont know how i can achive it:
public List<Wrapper> wrapperList {get; set;} public String currentRecordId {get; set;} public DokuBox() { currentRecordId = ApexPages.currentPage().getParameters().get('id'); if(wrapperList == null) { wrapperList = new List<Wrapper>(); for(Task a: [select Id, Subject, CreatedDate, Createdby.Name, Owner.Name, RecordType.Name, Status from Task where WhoId =: currentRecordId AND Subject LIKE 'E-Mail:%']) { wrapperList.add(new Wrapper(a, 'E-Mail')); } for(Task a: [select Id, Subject, CreatedDate, Createdby.Name, Owner.Name, RecordType.Name, Status from Task where WhoId =: currentRecordId AND (NOT Subject LIKE 'E-Mail:%')]) { wrapperList.add(new Wrapper(a, 'Aufgabe')); } for(Event b: [select Id, Subject, CreatedDate, StartDateTime, Createdby.Name, Owner.Name from Event where WhoId =: currentRecordId]) { wrapperList.add(new Wrapper(b, 'Termin')); } for(ContentDocumentLink d: [SELECT Id, ContentDocumentId, ContentDocument.Title, ContentDocument.createdDate, ContentDocument.Createdby.Name, ContentDocument.FileExtension FROM ContentDocumentLink WHERE LinkedEntityId =: currentRecordId AND ContentDocument.FileExtension = 'snote']) { wrapperList.add(new Wrapper(d, 'Notiz')); } for(ContentDocumentLink d: [SELECT Id, ContentDocumentId, ContentDocument.Title, ContentDocument.createdDate, ContentDocument.Createdby.Name, ContentDocument.FileExtension FROM ContentDocumentLink WHERE LinkedEntityId =: currentRecordId AND ContentDocument.FileExtension <> 'snote']) { wrapperList.add(new Wrapper(d, 'Datei')); } wrapperList.sort(); } } public class Wrapper implements Comparable { private final String objectLabel; private final Id id; private final String subject; private final DateTime createDate; private final String Ersteller; private final String Typ; private final String Status; public wrapper(Task t, String oName) { objectLabel = oName; id = t.Id; subject = t.Subject; createDate = t.CreatedDate; Ersteller = t.Owner.Name; Typ = t.RecordType.Name; Status = t.Status; } public wrapper(Event e, String oName) { objectLabel = oName; id = e.Id; subject = e.Subject; createDate = e.StartDateTime; Ersteller = e.Owner.Name; } public wrapper(ContentDocumentLink f, String oName) { objectLabel = oName; id = f.ContentDocumentId; subject = f.ContentDocument.Title; createDate = f.ContentDocument.CreatedDate; Ersteller = f.ContentDocument.CreatedBy.Name; Typ = f.ContentDocument.FileExtension; } public Id getId() { return id; } public String getSubject() { return subject; } public String getTyp() { return Typ; } public DateTime getCreatedDate() { return createDate; } public String getObjectLabel() { return objectLabel; } public String getErsteller() { return Ersteller; } public String getStatus() { return Status; }