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
SIVA KUMAR 507SIVA KUMAR 507 

Hey All i need Apex test class for the below code please help me!!

Class:
---------
public class AskEDD_casecommentcreation {
@InvocableMethod
    public static void ProcessBuilder_Call(list<Id> TaskId)
    {
        List<id> taskIds = new list<id>();
        list<CaseComment> CCList = new list<CaseComment>();
        list<Task> td = new list<Task>();
        list<caseFeed> fi = new list<caseFeed>();
        list<TaskFeed> ti = new list<TaskFeed>();
        list<id> caseIds = new list<id>();
        for(Id a : TaskId)
        {
            taskIds.add(a);
        }
        system.debug('Task Id is ****' +taskIds);
        list<Task> tasklist = [select id, Description, WhatId from Task where id in: TaskId];
        for (Task taskRecord : tasklist){
         caseIds.add(taskRecord.WhatId);   
             system.debug('Case Id is ****' +taskRecord.WhatId);
        }
        
        fi = [select id, parentId, Type from caseFeed where parentId IN: caseIds and Type = 'CaseCommentPost'];
        ti = [select id, parentId, Type from TaskFeed];
        
        system.debug('fi = '+fi);
        system.debug('ti = '+ti);

        
        for(task t : tasklist){
            system.debug('Task t Id is **** '+t);
            CaseComment cc = new CaseComment();
            cc.CommentBody = t.Description;
            cc.ParentId = t.WhatId;
            CCList.add(cc);

      Task Deletet = new Task();
            Deletet.id = t.id;
      td.add(Deletet);
        }
        insert CCList;
        system.debug('CCList is ****'+ CCList);
       // delete ti;
      //  delete fi;
      //  system.debug('Delete feedItem list is ******'+fi);
    //    delete tasklist;
        system.debug('Delete list is ******'+tasklist);
        
    }
}
Best Answer chosen by SIVA KUMAR 507
AbhinavAbhinav (Salesforce Developers) 
Hi Siva,

You can try below sample code after checking your implementation.
#SampleCode
@isTest
public class TestSample_AskEDD_casecommentcreation {
    
    static testMethod void test_ProcessBuilder_Call() {
        
        List<Id> taskId =new List<Id>();
        Case c = new Case();
        c.Status= 'New';
        c.Origin= 'Email';
        
        insert c;
        Task T = new Task();
        T.Type = 'Email';
        T.Description = 'testDesc'; 
        
        T.WhatId = c.Id;
        insert T;
        taskId.add(T.id);
         
        
        AskEDD_casecommentcreation.ProcessBuilder_Call(taskId);
        
    }
}


Hope above answer was helpful, Please mark as best answer so that it can help others in future.

Thanks!

All Answers

AbhinavAbhinav (Salesforce Developers) 
Hi Siva,

You can try below sample code after checking your implementation.
#SampleCode
@isTest
public class TestSample_AskEDD_casecommentcreation {
    
    static testMethod void test_ProcessBuilder_Call() {
        
        List<Id> taskId =new List<Id>();
        Case c = new Case();
        c.Status= 'New';
        c.Origin= 'Email';
        
        insert c;
        Task T = new Task();
        T.Type = 'Email';
        T.Description = 'testDesc'; 
        
        T.WhatId = c.Id;
        insert T;
        taskId.add(T.id);
         
        
        AskEDD_casecommentcreation.ProcessBuilder_Call(taskId);
        
    }
}


Hope above answer was helpful, Please mark as best answer so that it can help others in future.

Thanks!
This was selected as the best answer
SIVA KUMAR 507SIVA KUMAR 507
Hi Abhinav,

Thank you for Reply. And this Test Class Is Matched With My Requirement.
And I Have some Another Class can you please Help on that....?