0

I am trying to make a simple test class to get the code coverage. This is the class of the documentation in Salesforce which must be tested. Has anyone a sample for me :) ?

Best regards. Constantin

global class CreateIndividualFromContact implements Database.Batchable<sObject> {
global Database.Querylocator start(Database.BatchableContext BC) {
   //Query to fetch contacts that don't have Individual created. You may modify the query to add custom fields  
   //Please add  "IsPersonAccount = false" condition to below query to exclude person accounts
   return Database.getQueryLocator('Select FirstName, LastName, Salutation from Contact where IndividualId = NULL');
}

global void execute(Database.BatchableContext BC, List<Contact> contactList) { 
    Map<Id, Individual> individualRecordsToCreate = new Map<Id, Individual>();
    for(Contact con : contactList) {
        individualRecordsToCreate.put(con.Id, new Individual(FirstName = con.FirstName, LastName = con.LastName, Salutation=con.Salutation));
    }
    insert individualRecordsToCreate.values();
    for(Contact con : contactList) {
        con.IndividualId = individualRecordsToCreate.get(con.Id).Id;
    }
    update contactList;
}

global void finish(Database.BatchableContext BC) {}

This is what I am trying to create. It may be totally wrong..

 @isTest public class test class{ static testmethod void test_method1()
{ 
List<Contact> acts = new List<Contacts>(); for (integer i=0;i<200;i++)
{ 
Contact a= new Contact (FirstName=Test contact+i, LastName= Testq, salutation= Sehr geehrter Herr) acts.add(a);
} 
Test.StartTest(); insert acts; 
Test.StopTest(); // List<contact> inserted_acts [select FirstName, LastName, salutation where ID IN :acts]; for (Contact i_a : inserted_acts)
{ 
System.assertEquals() 
} 
}
  • What you have tried so far? – Santanu Boral Apr 29 '19 at 9:24
  • Hello, thank you for your fast answer. I tried nothing as I am a bloody beginner. I hope you guys can help out with some templates.. :) – Con Apr 29 '19 at 9:46
  • Please update your question with this code block – Lukas Lunow Apr 29 '19 at 10:29