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
Akash jena 3Akash jena 3 

what is the test class of this code

public with sharing class LeadConvertService {
    Private Final List<Lead__c> LEADS;
    
    LeadConvertService(List<Lead__c> leads){
        this.LEADS = leads;
    }
}
ANUTEJANUTEJ (Salesforce Developers) 
Hi Akash,

If you have a controller with simple constructor like this :

public class MyClass
{
    public MyClass()
    {
        //Do Something
    }
}

 Then you can write this test class :

@isTest
private class TestMyClass{
    @isTest
    private static void testClass()
    {
    MyClass controller = new MyClass() ;
    }
}
 
But if you have used standard controller like this :

public class MyAccountClass
{
    //Class Constructor        
        public MyAccountClass(ApexPages.StandardController controller)
    {
        //Do Something
    }
}
 

So you can test it like this :

@isTest
private class TestMyClass{
    @isTest
    private static void testClass()
    {
    //Standard controller of Account is just an example
    //Create a new instance of Account
    Account acc = new Account(Name = 'TestAccountName');

    //Insert the object virtually
    insert acc;

    //Create a new instance of standard controller
    ApexPages.StandardController sc = new ApexPages.standardController(acc);

    MyAccountClass controller = new MyAccountClass(sc);
    }
}
 
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
 
Akash jena 3Akash jena 3
I am getting this error
Akash jena 3Akash jena 3
I have tried this but not working

@istest
public class LeadConvertServiceTest {
    @testsetup
    private static void testClass(){
    Account acc = new Account(name='Test Account');
    insert acc;
    
    
    Lead__c Ld=new Lead__c(Name='Lead',Last_Name__c='Test',Company__c='xyz',Account__c=acc.id);
    insert Ld;
     
    }
    @isTest
    Private static void leadUpdate(){
        //Test.startTest();
        List<Lead__c> Ld = [SELECT id,Name from Lead__c LIMIT 1];
        //LeadConvertService Lcs = new LeadConvertService();
        LeadConvertService.LeadConvertService(Ld[0]);
        
    }
}
Akash jena 3Akash jena 3
hey anutej, its not working still getting error can you please help me 
Akash jena 3Akash jena 3
User-added image