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
Vijay A 8Vijay A 8 

Please help me test class for below controller

public class AddPersonCtrl {
    
    public Opportunity Opps;
    public Outside_People_Roles__c del;
    public Boolean refreshPage { get; set; }
    public List<Outside_People_Roles__c> addattendeeList {get;set;}
    public List<Outside_People_Roles__c> delattendeeList {get;set;}
    public List<Outside_People_Roles__c> attendeeList {get;set;}
    
    public Integer rowIndex {get;set;}
    public String currentRecordId;
    //public Boolean shouldRedirect {get;set;}
    
    public List<Outside_People_Roles__c> delAttendees {get; set;} 
    public AddPersonCtrl(ApexPages.StandardSetController controller) {
        currentRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        System.debug('currentRecordId'+currentRecordId);
        attendeelist=New List<Outside_People_Roles__c>();
        attendeeList.add(new Outside_People_Roles__c(Opportunity__c = currentRecordId));
        refreshPage = false;
        delattendeeList = new List<Outside_People_Roles__c>();
        delattendees = new List<Outside_People_Roles__c>();
    }
    public void addRow(){
        attendeeList.add(new Outside_People_Roles__c(Opportunity__c = currentRecordId));
    }
    public PageReference save(){
        upsert attendeeList;
        PageReference pr = new PageReference('/' +currentRecordId);        
        refreshPage = true;
        return pr;
    } 
    public void deleteRow(){
        rowIndex = Integer.valueOf(ApexPages.currentPage().getParameters().get('rowIndex'));
        System.debug('row be deleted ' + rowIndex );
        attendeeList.remove(rowIndex);    
    }
}

Thankyou Advance.
Best Answer chosen by Vijay A 8
AnudeepAnudeep (Salesforce Developers) 
Hi Vijay,

Please see the sample code below
 
@isTest
public class AddPersonCtrlTest {
    testmethod static void testme()
	{
		List <Outside_People_Roles__c> opList = new List<Outside_People_Roles__c>();
		Outside_People_Roles__c op = new Outside_People_Roles__c();
		op.Name='Test op' ;
                // Add required fields here
		opList.add(op);
                insert opList; ;
 
        test.startTest();
		
			Test.setCurrentPage(Page.yourVFPageName); //insert your VF page name here
			apexpages.standardsetcontroller std=new apexpages.StandardSetController(opList);
			AddPersonCtrl  adp = new AddPersonCtrl(std);
		        adp.addRow();
                        adp.save();
                        adp.deleteRow();
			
		test.stopTest();
    }
}

NOTE: The code provided is an example. Request you to please review and make modifications for your organization.

Let me know if this helps, if it does, please mark this answer as best so that others facing the same issue will find this information useful. Thank you