• Developer2016
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Hi Experts,

Please find below batch class i need test class. Please anyone help me regarding this. Thanks in advance.

global class SendPartnerGroupRequirementsBatch implements Database.Batchable<SObject>
{
   global static String response{get; set;}
   global List<Request__c> objLstRequest{get;set;}
   
    public SendPartnerGroupRequirementsBatch(List<Request__c> lstReq)
    {
        objLstRequest = lstReq;
    }
    global Database.QueryLocator  start(Database.BatchableContext bc) 
    {
        String query = 'SELECT Id FROM Request__c where Id in :objLstRequest';
        return Database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext BC, List<Request__c> scope)
    {
        for(Request__c objReq : scope)
        {
            response = WorkflowUtil.submitRequest(objReq.Id);
            String requestId= objReq.Id;
            if (response == 'Success') 
            {
                System.Queueable job = new SendPartnerGroupRequirementsBatchHandler(requestId);
                System.enqueueJob(job);
            }
        }
        
    }
    global void finish(Database.BatchableContext BC)
    {
        
    }

}
Hi Experts,
 
Please find below Class, Trigger, and Test Class.
At present with my test class, it cover class with 33% and Trigger 0% need test class code cover help.
Please anyone help me.
 

Apex Class:


public with sharing class TaskTriggerHandler {
 
    private boolean m_isExecuting = false;
    private integer BatchSize = 0;
 
    public TaskTriggerHandler(boolean isExecuting, integer size) {
        m_isExecuting = isExecuting;
        BatchSize = size;
    }
   
    public void OnAfterUpdate(Map<ID, Task> newRecordMap, Map<ID, Task> oldRecordMap) {
       
        //if one Task related to WorkflowInstance was closed, clase all others Tasks related to the WorkflowInstance
        set<String> workflowInstanceIds = new set<String>();
       
        Schema.DescribeSObjectResult result = Workflow_Instance__c.SObjectType.getDescribe();
       
        String prefix_WorkflowInstance = result.getKeyPrefix();
       
        for(Id newRecordId: newRecordMap.keySet()){
            Task newRecord = newRecordMap.get(newRecordId);
            Task oldRecord = oldRecordMap.get(newRecordId);
            if(newRecord.IsClosed && !oldRecord.IsClosed && newRecord.WhatId != null && String.valueOf( newRecord.WhatId ).substring(0,3) == prefix_WorkflowInstance ){
                workflowInstanceIds.add(newRecord.WhatId);
            }
        }
        if(workflowInstanceIds.size() > 0) WorkflowUtil.closeTasks( workflowInstanceIds );
       
    }
}
 
 
 
Trigger:
 
trigger TaskTrigger on Task (after update) {
    TaskTriggerHandler handler = new TaskTriggerHandler(Trigger.isExecuting, Trigger.size);
    if(Trigger.isUpdate && Trigger.isAfter)  handler.OnAfterUpdate(Trigger.newMap, Trigger.oldMap);
}
 


 
Test Class:
 
@isTest
private class TaskTriggerHandlerTest {
 
    @isTest
    private static void TaskTriggerHandlerTest(){
       
        User u = [select id,Primary_UBE_Id__c from User where id=:UserInfo.getUserId()];
        u.Primary_UBE_Id__c = '114';
        update u;
 
        boolean m_isExecuting = false;
       
        //m_isExecuting = isExecuting;
        //BatchSize = size;
 
        Test.startTest();
        Test.stopTest();
    }
   
    @isTest
    private static void OnAfterUpdateTest(){
       
        User u = [select id,Primary_UBE_Id__c from User where id=:UserInfo.getUserId()];
        u.Primary_UBE_Id__c = '114';
        update u;
      
        Request__c request = new Request__c(name = 'test');
        insert request;
       
        Workflow_Instance__c workflowInstance = new Workflow_Instance__c(Request__c = request.Id);
        insert workflowInstance;
       
        Task told = new Task(Ownerid = U.id, Subject = 'Test', Whatid = workflowInstance.id, Status = 'Pending', Priority = 'Low', Description = 'Test');
        insert told;
       
        Task tnew = new Task(Ownerid = U.id, Subject = 'Test', Whatid = workflowInstance.id, Status = 'Closed', Priority = 'Low', Description = 'Test');
        insert tnew;
        
        Map<ID, Task> newRecordMap = new map<ID, Task>();       
        Map<ID, Task> oldRecordMap = new map<ID, Task>();
       
        set<String> workflowInstanceIds = new set<String>();
       
        Test.startTest();
            TaskTriggerHandler handler = new TaskTriggerHandler(Trigger.isExecuting, Trigger.size);
            //if(Trigger.isUpdate && Trigger.isAfter)  handler.OnAfterUpdate(Trigger.newMap, Trigger.oldMap);
        Test.stopTest();
    }
 
}
 
Hi Experts,
Below peace of apex code not covered in test class. Please anybody help me.

@RemoteAction
    global static String createNewUbeRelationship(RelationshipUtil.Relationship uuRelationship, String requestorId, String responderId) 
    {
        SavePoint savePoint = Database.setSavePoint();
        String message = '';
        try 
        {
            if(uuRelationship != null && requestorId != null && responderId != null) 
            {
                Trading_Partner_Relationship__c newUURelationship = 
                    new Trading_Partner_Relationship__c(    Name            = uuRelationship.name, 
                                                            Requestor__c    = requestorId,  
                                                            Responder__c    = responderId, 
                                                            Status__c       = 'Pending',//uuRelationship.relationshipStatus, 
                                                            Type__c         = uuRelationship.relationshipType);
                Data.create(newUURelationship);
                MessengerUURelationship.insertNonUniversalId(newUURelationship.Id, uuRelationship.nonUniversalIds);   
                set<String> uuRelationshiptags = new set<String>();
                uuRelationshiptags.addAll( uuRelationship.tags );          
                MessengerUURelationship.insertRelationshipAttributesTags(newUURelationship.Id, uuRelationshiptags); 
                
                MessengerUURelationship.sendInFuture(new Set<Id>{ newUURelationship.Id }); 
                
                message = 'Reciprocal Trading Partner Relationship created successfully.';

            }   else message = 'Error';
        } catch (Exception e) 
        {
            Database.rollback(savePoint);
            Util.log(e);
            message = 'Error: ' + e.getMessage() + ' -- ' + e.getStackTraceString();
        } 
        return message;    
    }
}

Thanks in advance
 
Hi Experts,
Below peace of apex code not covered in test class. Please anybody help me.

@RemoteAction
    global static String createNewUbeRelationship(RelationshipUtil.Relationship uuRelationship, String requestorId, String responderId) 
    {
        SavePoint savePoint = Database.setSavePoint();
        String message = '';
        try 
        {
            if(uuRelationship != null && requestorId != null && responderId != null) 
            {
                Trading_Partner_Relationship__c newUURelationship = 
                    new Trading_Partner_Relationship__c(    Name            = uuRelationship.name, 
                                                            Requestor__c    = requestorId,  
                                                            Responder__c    = responderId, 
                                                            Status__c       = 'Pending',//uuRelationship.relationshipStatus, 
                                                            Type__c         = uuRelationship.relationshipType);
                Data.create(newUURelationship);
                MessengerUURelationship.insertNonUniversalId(newUURelationship.Id, uuRelationship.nonUniversalIds);   
                set<String> uuRelationshiptags = new set<String>();
                uuRelationshiptags.addAll( uuRelationship.tags );          
                MessengerUURelationship.insertRelationshipAttributesTags(newUURelationship.Id, uuRelationshiptags); 
                
                MessengerUURelationship.sendInFuture(new Set<Id>{ newUURelationship.Id }); 
                
                message = 'Reciprocal Trading Partner Relationship created successfully.';

            }   else message = 'Error';
        } catch (Exception e) 
        {
            Database.rollback(savePoint);
            Util.log(e);
            message = 'Error: ' + e.getMessage() + ' -- ' + e.getStackTraceString();
        } 
        return message;    
    }
}

Thanks in advance