Skip to main content
added 236 characters in body
Source Link
peXeq
  • 469
  • 1
  • 11
  • 37
@isTest
private class DokuBox_Test {
    
    static testMethod void testMethod1() {

        DateTime cur=System.now();
        
        Account acc = new Account(Name = 'Test Account');
        insert acc;
        
        Contact con = new Contact(Firstname = 'John', Lastname = 'Doe');
        insert con;
        
        Task tsk = new Task(
            Subject = 'Call', 
            ActivityDate = Date.today().addDays(-1), 
            Description = 'Test', 
            WhoId = acc.Id
        );
        insert tsk;
        
        Event evt = new Event(
            WhoId = acc.id,
            Subject = 'Strategy',
            StartDateTime = Date.newInstance(cur.year(), cur.month(), 1) + 1,
            EndDateTime = Date.newInstance(cur.year(), cur.month(), 1 + 1)
        );
        insert evt;
        
        ContentVersion conVer = new ContentVersion(
            Title = 'Penguins',
            PathOnClient = 'Penguins.docx',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true,
            Vertraulichkeitsstufe__c = 'Intern',
            Dokumentenklasse__c = 'Geschäftsbrief'
        );
        insert conVer;  
        
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = acc.id;
        cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: conVer.id].ContentDocumentId;
        cdl.shareType = 'I';
        insert cdl;
        
        PageReference DokuBox_6v = Page.DokuBox_6v; // Assuming that the VF Page name is DokuBoxPage
        Test.setCurrentPage(DokuBox_6v);
        ApexPages.currentPage().getParameters().put('id', con.Id);
        DokuBox_6 controller = new DokuBox_6();
        System.assert(!controller.wrapperList.isEmpty());

        Test.setCurrentPage(DokuBox_6v);
        ApexPages.currentPage().getParameters().put('id', acc.Id);
        DokuBox_6 controller2 = new DokuBox_6();
              
        System.assert(!controller2.wrapperList.isEmpty());
    }
}
@isTest
private class DokuBox_Test {
    
    static testMethod void testMethod1() {

        DateTime cur=System.now();
        
        Account acc = new Account(Name = 'Test Account');
        insert acc;
        
        Contact con = new Contact(Firstname = 'John', Lastname = 'Doe');
        insert con;
        
        Task tsk = new Task(
            Subject = 'Call', 
            ActivityDate = Date.today().addDays(-1), 
            Description = 'Test', 
            WhoId = acc.Id
        );
        insert tsk;
        
        Event evt = new Event(
            WhoId = acc.id,
            Subject = 'Strategy',
            StartDateTime = Date.newInstance(cur.year(), cur.month(), 1) + 1,
            EndDateTime = Date.newInstance(cur.year(), cur.month(), 1 + 1)
        );
        insert evt;
        
        ContentVersion conVer = new ContentVersion(
            Title = 'Penguins',
            PathOnClient = 'Penguins.docx',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true,
            Vertraulichkeitsstufe__c = 'Intern',
            Dokumentenklasse__c = 'Geschäftsbrief'
        );
        insert conVer;  
        
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = acc.id;
        cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: conVer.id].ContentDocumentId;
        cdl.shareType = 'I';
        insert cdl;
        
        PageReference DokuBox_6v = Page.DokuBox_6v; // Assuming that the VF Page name is DokuBoxPage
        Test.setCurrentPage(DokuBox_6v);
        ApexPages.currentPage().getParameters().put('id', con.Id);
        DokuBox_6 controller = new DokuBox_6();
        System.assert(!controller.wrapperList.isEmpty());

    }
}
@isTest
private class DokuBox_Test {
    
    static testMethod void testMethod1() {

        DateTime cur=System.now();
        
        Account acc = new Account(Name = 'Test Account');
        insert acc;
        
        Contact con = new Contact(Firstname = 'John', Lastname = 'Doe');
        insert con;
        
        Task tsk = new Task(
            Subject = 'Call', 
            ActivityDate = Date.today().addDays(-1), 
            Description = 'Test', 
            WhoId = acc.Id
        );
        insert tsk;
        
        Event evt = new Event(
            WhoId = acc.id,
            Subject = 'Strategy',
            StartDateTime = Date.newInstance(cur.year(), cur.month(), 1) + 1,
            EndDateTime = Date.newInstance(cur.year(), cur.month(), 1 + 1)
        );
        insert evt;
        
        ContentVersion conVer = new ContentVersion(
            Title = 'Penguins',
            PathOnClient = 'Penguins.docx',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true,
            Vertraulichkeitsstufe__c = 'Intern',
            Dokumentenklasse__c = 'Geschäftsbrief'
        );
        insert conVer;  
        
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = acc.id;
        cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: conVer.id].ContentDocumentId;
        cdl.shareType = 'I';
        insert cdl;
        
        PageReference DokuBox_6v = Page.DokuBox_6v; // Assuming that the VF Page name is DokuBoxPage
        Test.setCurrentPage(DokuBox_6v);
        ApexPages.currentPage().getParameters().put('id', con.Id);
        DokuBox_6 controller = new DokuBox_6();
        System.assert(!controller.wrapperList.isEmpty());

        Test.setCurrentPage(DokuBox_6v);
        ApexPages.currentPage().getParameters().put('id', acc.Id);
        DokuBox_6 controller2 = new DokuBox_6();
              
        System.assert(!controller2.wrapperList.isEmpty());
    }
}
added 283 characters in body
Source Link
peXeq
  • 469
  • 1
  • 11
  • 37
@isTest
private class DokuBox_Test {
    
    static testMethod void testMethod1() {

        DateTime cur=System.now();
        
        Account acc = new Account(Name = 'Test Account');
        insert acc;
        
        Contact con = new Contact(Firstname = 'John', Lastname = 'Doe');
        insert con;
        
        Task tsk = new Task(
            Subject = 'Call', 
            ActivityDate = Date.today().addDays(-1), 
            Description = 'Test', 
            WhatIdWhoId = acc.Id
        );
        insert tsk;
        
        Event evt = new Event(
            WhatIdWhoId = acc.id,
            Subject = 'Strategy',
            StartDateTime = Date.newInstance(cur.year(), cur.month(), 1) + 1,
            EndDateTime = Date.newInstance(cur.year(), cur.month(), 1 + 1)
        );
        insert evt;
        
        ContentVersion conVer = new ContentVersion(
            Title = 'Penguins',
            PathOnClient = 'Penguins.docx',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true,
            Vertraulichkeitsstufe__c = 'Intern',
            Dokumentenklasse__c = 'Geschäftsbrief'
        );
        insert conVer;  
        
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = acc.id;
        cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: conVer.id].ContentDocumentId;
        cdl.shareType = 'I';
        insert cdl;
        
        PageReference DokuBox_6v = Page.DokuBox_6v; // Assuming that the VF Page name is DokuBoxPage
        Test.setCurrentPage(DokuBox_6v);
        ApexPages.currentPage().getParameters().put('id', con.Id);
        DokuBox_6 D6controller = new DokuBox_6();
        System.assert(!controller.wrapperList.isEmpty());

    }
}
@isTest
private class DokuBox_Test {
    
    static testMethod void testMethod1() {

        DateTime cur=System.now();
        
        Account acc = new Account(Name = 'Test Account');
        insert acc;
        
        Contact con = new Contact(Firstname = 'John', Lastname = 'Doe');
        insert con;
        
        Task tsk = new Task(
            Subject = 'Call', 
            ActivityDate = Date.today().addDays(-1), 
            Description = 'Test', 
            WhatId = acc.Id
        );
        insert tsk;
        
        Event evt = new Event(
            WhatId = acc.id,
            Subject = 'Strategy',
            StartDateTime = Date.newInstance(cur.year(), cur.month(), 1) + 1,
            EndDateTime = Date.newInstance(cur.year(), cur.month(), 1 + 1)
        );
        insert evt;
        
        ContentVersion conVer = new ContentVersion(
            Title = 'Penguins',
            PathOnClient = 'Penguins.docx',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true,
            Vertraulichkeitsstufe__c = 'Intern',
            Dokumentenklasse__c = 'Geschäftsbrief'
        );
        insert conVer;  
        
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = acc.id;
        cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: conVer.id].ContentDocumentId;
        cdl.shareType = 'I';
        insert cdl;
        
        DokuBox_6 D6 = new DokuBox_6();

    }
}
@isTest
private class DokuBox_Test {
    
    static testMethod void testMethod1() {

        DateTime cur=System.now();
        
        Account acc = new Account(Name = 'Test Account');
        insert acc;
        
        Contact con = new Contact(Firstname = 'John', Lastname = 'Doe');
        insert con;
        
        Task tsk = new Task(
            Subject = 'Call', 
            ActivityDate = Date.today().addDays(-1), 
            Description = 'Test', 
            WhoId = acc.Id
        );
        insert tsk;
        
        Event evt = new Event(
            WhoId = acc.id,
            Subject = 'Strategy',
            StartDateTime = Date.newInstance(cur.year(), cur.month(), 1) + 1,
            EndDateTime = Date.newInstance(cur.year(), cur.month(), 1 + 1)
        );
        insert evt;
        
        ContentVersion conVer = new ContentVersion(
            Title = 'Penguins',
            PathOnClient = 'Penguins.docx',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true,
            Vertraulichkeitsstufe__c = 'Intern',
            Dokumentenklasse__c = 'Geschäftsbrief'
        );
        insert conVer;  
        
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = acc.id;
        cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: conVer.id].ContentDocumentId;
        cdl.shareType = 'I';
        insert cdl;
        
        PageReference DokuBox_6v = Page.DokuBox_6v; // Assuming that the VF Page name is DokuBoxPage
        Test.setCurrentPage(DokuBox_6v);
        ApexPages.currentPage().getParameters().put('id', con.Id);
        DokuBox_6 controller = new DokuBox_6();
        System.assert(!controller.wrapperList.isEmpty());

    }
}

I don't know how can I test my contentdocumentlink, in the log I got the information EXCEPTION_THROWN [18]|System.QueryException: Implementation restriction: ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's using the IN operator.

EXCEPTION_THROWN [18]|System.QueryException: Implementation restriction: ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's using the IN operator.

but I think I only selected one record.

Main class

public class DokuBox_6 {
    
    public List<Wrapper> wrapperList {get; set;}
    public String currentRecordId {get; set;}
    
    public DokuBox_6() {
        currentRecordId = ApexPages.currentPage().getParameters().get('id');
        
        if(wrapperList == null) {
            wrapperList = new List<Wrapper>();
            
            for(Task a: [select Id, Subject, CreatedDate, Createdby.Name, RecordType.Name from Task where WhoId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(a, 'Task'));
            }
            for(Event b: [select Id, Subject, CreatedDate, Createdby.Name from Event where WhoId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(b, 'Event'));
            }
            for(ContentDocumentLink d: [SELECT Id, ContentDocumentId, ContentDocument.Title, ContentDocument.createdDate, ContentDocument.Createdby.Name, ContentDocument.FileExtension FROM ContentDocumentLink WHERE LinkedEntityId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(d, 'Note/File'));
            }
            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;
        
        public wrapper(Task t, String oName) { 
            objectLabel     = oName;
            id              = t.Id;
            subject         = t.Subject;
            createDate      = t.CreatedDate;
            Ersteller       = t.CreatedBy.Name;
            Typ             = t.RecordType.Name;
        }
        
        public wrapper(Event e, String oName) {
            objectLabel     = oName;
            id              = e.Id;
            subject         = e.Subject;
            createDate      = e.CreatedDate;
            Ersteller       = e.CreatedBy.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 Integer compareTo(Object compareTo) {
            Wrapper compareToActivity = (Wrapper) compareTo;
            DateTime compareToCreateDate = compareToActivity.getCreatedDate();
            if (createDate > compareToCreateDate) {
                return -1;
            }
            if (createDate < compareToCreateDate) {
                return 1;
            }
            return 0;
        }
    }
    
}

Test class

public class DokuBox_6 {
    
    public List<Wrapper> wrapperList {get; set;}
    public String currentRecordId {get; set;}
    
    public DokuBox_6() {
        currentRecordId = ApexPages.currentPage().getParameters().get('id');
        
        if(wrapperList == null) {
            wrapperList = new List<Wrapper>();
            
            for(Task a: [select Id, Subject, CreatedDate, Createdby.Name, RecordType.Name from Task where WhoId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(a, 'Task'));
            }
            for(Event b: [select Id, Subject, CreatedDate, Createdby.Name from Event where WhoId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(b, 'Event'));
            }          
            for(ContentDocumentLink d: [SELECT Id, ContentDocumentId, ContentDocument.Title, ContentDocument.createdDate, ContentDocument.Createdby.Name, ContentDocument.FileExtension FROM ContentDocumentLink WHERE LinkedEntityId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(d, 'Note/File'));
            }          
            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;
        
        public wrapper(Task t, String oName) { 
            objectLabel     = oName;
            id              = t.Id;
            subject         = t.Subject;
            createDate      = t.CreatedDate;
            Ersteller       = t.CreatedBy.Name;
            Typ             = t.RecordType.Name;
        }
        
        public wrapper(Event e, String oName) {
            objectLabel     = oName;
            id              = e.Id;
            subject         = e.Subject;
            createDate      = e.CreatedDate;
            Ersteller       = e.CreatedBy.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 Integer compareTo(Object compareTo) {
            Wrapper compareToActivity = (Wrapper) compareTo;
            DateTime compareToCreateDate = compareToActivity.getCreatedDate();
            if (createDate > compareToCreateDate) {
                return -1;
            }
            if (createDate < compareToCreateDate) {
                return 1;
            }
            return 0;
        }
    }
    
}



@isTest
private class DokuBox_Test {
    
    static testMethod void testMethod1() {
           
        DateTime cur=System.now();
        
        Account acc = new Account(Name = 'Test Account');
        insert acc;
        
        Contact con = new Contact(Firstname = 'John', Lastname = 'Doe');
        insert con;
        
        Task tsk = new Task(
            Subject = 'Call', 
            ActivityDate = Date.today().addDays(-1), 
            Description = 'Test', 
            WhatId = acc.Id
        );
        insert tsk;
        
        Event evt = new Event(
            WhatId = acc.id,
            Subject = 'Strategy',
            StartDateTime = Date.newInstance(cur.year(), cur.month(), 1) + 1,
            EndDateTime = Date.newInstance(cur.year(), cur.month(), 1 + 1)
        );
        insert evt;
        
        ContentVersion conVer = new ContentVersion(
            Title = 'Penguins',
            PathOnClient = 'Penguins.docx',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true,
            Vertraulichkeitsstufe__c = 'Intern',
            Dokumentenklasse__c = 'Geschäftsbrief'
        );
        insert conVer;  
        
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = acc.id;
        cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: conVer.id].ContentDocumentId;
        cdl.shareType = 'I';
        insert cdl;         
        
        DokuBox_6 D6 = new DokuBox_6();
  
    }
}

I don't know how can I test my contentdocumentlink, in the log I got the information EXCEPTION_THROWN [18]|System.QueryException: Implementation restriction: ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's using the IN operator. but I think I only selected one record.

public class DokuBox_6 {
    
    public List<Wrapper> wrapperList {get; set;}
    public String currentRecordId {get; set;}
    
    public DokuBox_6() {
        currentRecordId = ApexPages.currentPage().getParameters().get('id');
        
        if(wrapperList == null) {
            wrapperList = new List<Wrapper>();
            
            for(Task a: [select Id, Subject, CreatedDate, Createdby.Name, RecordType.Name from Task where WhoId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(a, 'Task'));
            }
            for(Event b: [select Id, Subject, CreatedDate, Createdby.Name from Event where WhoId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(b, 'Event'));
            }          
            for(ContentDocumentLink d: [SELECT Id, ContentDocumentId, ContentDocument.Title, ContentDocument.createdDate, ContentDocument.Createdby.Name, ContentDocument.FileExtension FROM ContentDocumentLink WHERE LinkedEntityId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(d, 'Note/File'));
            }          
            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;
        
        public wrapper(Task t, String oName) { 
            objectLabel     = oName;
            id              = t.Id;
            subject         = t.Subject;
            createDate      = t.CreatedDate;
            Ersteller       = t.CreatedBy.Name;
            Typ             = t.RecordType.Name;
        }
        
        public wrapper(Event e, String oName) {
            objectLabel     = oName;
            id              = e.Id;
            subject         = e.Subject;
            createDate      = e.CreatedDate;
            Ersteller       = e.CreatedBy.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 Integer compareTo(Object compareTo) {
            Wrapper compareToActivity = (Wrapper) compareTo;
            DateTime compareToCreateDate = compareToActivity.getCreatedDate();
            if (createDate > compareToCreateDate) {
                return -1;
            }
            if (createDate < compareToCreateDate) {
                return 1;
            }
            return 0;
        }
    }
    
}



@isTest
private class DokuBox_Test {
    
    static testMethod void testMethod1() {
           
        DateTime cur=System.now();
        
        Account acc = new Account(Name = 'Test Account');
        insert acc;
        
        Contact con = new Contact(Firstname = 'John', Lastname = 'Doe');
        insert con;
        
        Task tsk = new Task(
            Subject = 'Call', 
            ActivityDate = Date.today().addDays(-1), 
            Description = 'Test', 
            WhatId = acc.Id
        );
        insert tsk;
        
        Event evt = new Event(
            WhatId = acc.id,
            Subject = 'Strategy',
            StartDateTime = Date.newInstance(cur.year(), cur.month(), 1) + 1,
            EndDateTime = Date.newInstance(cur.year(), cur.month(), 1 + 1)
        );
        insert evt;
        
        ContentVersion conVer = new ContentVersion(
            Title = 'Penguins',
            PathOnClient = 'Penguins.docx',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true,
            Vertraulichkeitsstufe__c = 'Intern',
            Dokumentenklasse__c = 'Geschäftsbrief'
        );
        insert conVer;  
        
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = acc.id;
        cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: conVer.id].ContentDocumentId;
        cdl.shareType = 'I';
        insert cdl;         
        
        DokuBox_6 D6 = new DokuBox_6();
  
    }
}

I don't know how can I test my contentdocumentlink, in the log I got the information

EXCEPTION_THROWN [18]|System.QueryException: Implementation restriction: ContentDocumentLink requires a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or multiple Id's using the IN operator.

but I think I only selected one record.

Main class

public class DokuBox_6 {
    
    public List<Wrapper> wrapperList {get; set;}
    public String currentRecordId {get; set;}
    
    public DokuBox_6() {
        currentRecordId = ApexPages.currentPage().getParameters().get('id');
        
        if(wrapperList == null) {
            wrapperList = new List<Wrapper>();
            
            for(Task a: [select Id, Subject, CreatedDate, Createdby.Name, RecordType.Name from Task where WhoId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(a, 'Task'));
            }
            for(Event b: [select Id, Subject, CreatedDate, Createdby.Name from Event where WhoId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(b, 'Event'));
            }
            for(ContentDocumentLink d: [SELECT Id, ContentDocumentId, ContentDocument.Title, ContentDocument.createdDate, ContentDocument.Createdby.Name, ContentDocument.FileExtension FROM ContentDocumentLink WHERE LinkedEntityId =: currentRecordId limit 10]) {
                wrapperList.add(new Wrapper(d, 'Note/File'));
            }
            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;
        
        public wrapper(Task t, String oName) { 
            objectLabel     = oName;
            id              = t.Id;
            subject         = t.Subject;
            createDate      = t.CreatedDate;
            Ersteller       = t.CreatedBy.Name;
            Typ             = t.RecordType.Name;
        }
        
        public wrapper(Event e, String oName) {
            objectLabel     = oName;
            id              = e.Id;
            subject         = e.Subject;
            createDate      = e.CreatedDate;
            Ersteller       = e.CreatedBy.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 Integer compareTo(Object compareTo) {
            Wrapper compareToActivity = (Wrapper) compareTo;
            DateTime compareToCreateDate = compareToActivity.getCreatedDate();
            if (createDate > compareToCreateDate) {
                return -1;
            }
            if (createDate < compareToCreateDate) {
                return 1;
            }
            return 0;
        }
    }
    
}

Test class

@isTest
private class DokuBox_Test {
    
    static testMethod void testMethod1() {

        DateTime cur=System.now();
        
        Account acc = new Account(Name = 'Test Account');
        insert acc;
        
        Contact con = new Contact(Firstname = 'John', Lastname = 'Doe');
        insert con;
        
        Task tsk = new Task(
            Subject = 'Call', 
            ActivityDate = Date.today().addDays(-1), 
            Description = 'Test', 
            WhatId = acc.Id
        );
        insert tsk;
        
        Event evt = new Event(
            WhatId = acc.id,
            Subject = 'Strategy',
            StartDateTime = Date.newInstance(cur.year(), cur.month(), 1) + 1,
            EndDateTime = Date.newInstance(cur.year(), cur.month(), 1 + 1)
        );
        insert evt;
        
        ContentVersion conVer = new ContentVersion(
            Title = 'Penguins',
            PathOnClient = 'Penguins.docx',
            VersionData = Blob.valueOf('Test Content'),
            IsMajorVersion = true,
            Vertraulichkeitsstufe__c = 'Intern',
            Dokumentenklasse__c = 'Geschäftsbrief'
        );
        insert conVer;  
        
        ContentDocumentLink cdl = New ContentDocumentLink();
        cdl.LinkedEntityId = acc.id;
        cdl.ContentDocumentId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =: conVer.id].ContentDocumentId;
        cdl.shareType = 'I';
        insert cdl;
        
        DokuBox_6 D6 = new DokuBox_6();

    }
}
Source Link
peXeq
  • 469
  • 1
  • 11
  • 37
Loading