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
Shruthi NarsiShruthi Narsi 

Test class failed to display list of leads

Can anyone help me with the test class to add parten lead list on account page

Below is my apex class

public class PartnerLeadController {
    public Account acc{get;set;}
    public List<Lead> LeadList{get;set;}  
    Set<String> UserContactId = new Set<String>(); 
    public PartnerLeadController(ApexPages.StandardController stdController) {
        LeadList = new List<Lead>();
        this.acc = (Account)stdController.getRecord();
        list<contact> conlist=[Select Id From Contact WHERE AccountId =:acc.Id]; 
        for(User u: [Select Id, Name, ContactId FROM USER WHERE isactive=TRUE AND ContactId In:conlist]){
            UserContactId.add(u.Id);
        }
        LeadList = [select id,Name, OwnerId, Owner.Name,LeadSource,CRM_User__r.Name,CRM_User__r.Id, Status, Account__c,LastName, Account__r.id,Account__r.OwnerId
                    from Lead 
                    where  CRM_User__c !=null And Account__c=: acc.Id AND LeadSource='Partner'];
    }
}

Test class

@isTest
public class PartnerLeadControllerTestClass {
    
    static testMethod void leadscontroller()
    {        
        Account myaccount = new Account (name='Test');
        insert myaccount;
        
        PageReference pageRef = Page.PartnerleadList;
        pageRef.getparameters().put('recordId', myaccount.Id);  
        Test.setCurrentPage(pageRef);
        
        Apexpages.StandardController sc = new Apexpages.StandardController(myaccount);
        PartnerLeadController partlead = new PartnerLeadController(sc);   
        partlead.getlead();
        partlead.initlead();
    }
   
}

Vf page

<apex:page standardController="Account" extensions="PartnerLeadController" lightningStylesheets="true" sidebar="false" >
    <apex:form >
        <apex:pageBlock rendered="true">
            <apex:pageBlockTable value="{!LeadList}" var="ld">
                <apex:column >
                    {!ld.Name}
                    <apex:facet name="header">Lead Name</apex:facet>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>  
    </apex:form>
</apex:page>