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
RajashriRajashri 

Set Parameter Value to test the code

Hi

How can i set the parameter value in controller to Test my below code.

public with sharing class singleListView {
    public Campaign camp {get; set; }
    Public Lead lead{get;set;}
    List<CampaignMember>  CampaignMember = new List<CampaignMember>(); 
    public singleListView(ApexPages.StandardController controller) {
       camp = (Campaign)controller.getRecord();
       
          
          
           System.debug(camp.Id);
           
    }
    public List<Schema.Lead> CampaignMembers;
    public List<Schema.Lead> getCampaignMembers() {
       System.debug(camp.Id);
   CampaignMembers=[Select Id,Name,(Select id, Campaign.Name,Contact.Phone,Lead.FirstName,Lead.LastName,LeadID,Lead.Phone,Lead.Email, Lastmodifieddate,Status,CampaignId,Campign_ID__c,Lead.MobilePhone  From CampaignMembers where CampaignId =:camp.Id and Status != '' and LeadId != null), 
(Select Subject, Id,lastModifiedDate From ActivityHistories  where lastModifiedDate !=null and Subject !=null order by LastModifiedDate desc limit 1) 
From Lead  where Name !=NULL and Id='00Q90000008fA5OEAU' order by LastModifiedDate desc];
       return CampaignMembers;
 
         }     
          }
pconpcon
To do this you'll need to generate a standard controller for the object
 
public testmethod void myTest() {
     // Data to setup campaign object

     Campaign testCampaign = new Campaign();
     insert testCampaign;

     Test.startTest();

     Apex.StandardController sc = new ApexPages.StandardController(testCampaign);
     singleListView controller = new singleListView(sc);

     // Rest of test

     Test.stopTest();
}

NOTE: This code has not been tested and may contain typographical or logical errors