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
sp13sp13 

check method in test class

how can i check the line showProject4 = true in my test class?

public Boolean showProject4 {get;set;}
public void ProjButton3() { if(leave.Project_1__c != null && leave.Project_2__c != null && leave.Project_3__c != null) { showProject4 = true; } else { ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please select projects.'); ApexPages.addMessage(myMsg); showProject4 = false; } }

i have this in my test class: 

controller.ProjButton3();

but when i check it in the devconsole, line showProject4 = true isn't checked.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
MiddhaMiddha

In your test method, before you call controller.ProjButton3();, make sure that you create an instance of leave oebject and populate the values for all three i.e. Project_1__c,Project_2__c  and Project_3__c.