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
Tony MontanaTony Montana 

I have created the following class

public class BEO_Send_Compliance_Survey_Class {
   
    @InvocableMethod
    public static void createParticipantRecord(List<Id> varRequestId)
    {
         Id SurveyRecipientRecordTypeId = Schema.SObjectType.Participant__c.getRecordTypeInfosByName().get('Survey Recipient').getRecordTypeId();
         Map<Id, Participant__c> createParticipants = new Map<Id,  Participant__c>();

         List<Contact> theContacts =[select id, name from contact where NT_Login_Name__c != null and Former_Employee__c = false and Management_Level_Type__c in ('VP','Director')];

        //FOR loop to run through Contact records in  theContacts

    for(Contact c : theContacts){
        createParticipants.put(c.Id, new Participant__c(Participant__c = c.Id, Request__c = varRequestId[0],RecordTypeId=SurveyRecipientRecordTypeId));
    }

    //Insert the values (individuals) in the createTheseIndividuals map

    insert createParticipants.values();
        
        
        system.debug('hi i m here');
    }
   
    
    
    
}

What should be the corresponding class with at least 80% coverage. ?

Thanks,
TM
Best Answer chosen by Tony Montana
mukesh guptamukesh gupta
Hi Tonny,

Please use below code
 
@isTest
private class BEO_Send_Compliance_Survey_ClassTest {

    private static testMethod void doTest() {

        Test.startTest();
        Lead l = new Lead(LastName = 'Test Lead',
                     Company = 'Test Company',
                     IsRecruitmentLead__c = True);
        insert l;
		
		Set<Id>varRequestId = new Set<Id>();
		varRequestId.add(l.id);
		
		contact con = new contact();
		con.name = 'mukesh',
		con.NT_Login_Name__c = 'test', 
		Former_Employee__c = false,
		Management_Level_Type__c = 'VP Director',
		
		insert con;
		
		Test.startTest();
        BEO_Send_Compliance_Survey_Class.createParticipantRecord(varRequestId);

        Test.stopTest();

       

    }
}

if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 

All Answers

mukesh guptamukesh gupta
Hi Tonny,

Please use below code
 
@isTest
private class BEO_Send_Compliance_Survey_ClassTest {

    private static testMethod void doTest() {

        Test.startTest();
        Lead l = new Lead(LastName = 'Test Lead',
                     Company = 'Test Company',
                     IsRecruitmentLead__c = True);
        insert l;
		
		Set<Id>varRequestId = new Set<Id>();
		varRequestId.add(l.id);
		
		contact con = new contact();
		con.name = 'mukesh',
		con.NT_Login_Name__c = 'test', 
		Former_Employee__c = false,
		Management_Level_Type__c = 'VP Director',
		
		insert con;
		
		Test.startTest();
        BEO_Send_Compliance_Survey_Class.createParticipantRecord(varRequestId);

        Test.stopTest();

       

    }
}

if you need any assistanse, Please let me know!!


Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh

 
This was selected as the best answer
Suraj Tripathi 47Suraj Tripathi 47
Hi,

Please try below code:-

    @isTest
private class TestBEO_Send_Compliance_Survey_Class {

    private static void testCreateParticipantRecord() {

        
        Lead lead1 = new Lead();
        lead1.LastName = 'Test Lead',
        lead1.Company = 'Test Company',
        lead1.IsRecruitmentLead__c = True);
        insert lead1;
        
        
        contact contact1 = new contact();
        contact1.name = 'TestContact';
        contact1.NT_Login_Name__c = 'test1';
        contact1.Former_Employee__c = false;
        contact1.Management_Level_Type__c = 'VP Director';
        
        insert contact1;
        
        Test.startTest();
        BEO_Send_Compliance_Survey_Class.createParticipantRecord(lead1.id);

        Test.stopTest();
    }
}

Please mark it as Best Answer if it helps you.

Thanks & Regards
Suraj Tripathi
    
 
Andrew GAndrew G
wonder if people still know how to do asserts?

coverage without asserts?  not worth the effort of writing