
3 answers

Hi AbhilashYou will have to add @testVisible annotation in your controller as the method is private. PFB the test class which will give you 100% code coverage.Apex class:
Test class:Public class getAccounts{
@testVisible private String getAccountRecords(String AccuntId, String accountFor){
String recordId;
List<Account> accList =[Select id,Name,phone from Account LIMIT 1];
if(!accList.isEmpty()){
recordId = accList[0].id;
}
return recordId;
}
}
Note: I have took value of parameter accountFor as XYZ for test purpose. You can modify as per your requirement. Also there is no standard field - Email present on Account object, if it is custom field then please append __c and in test class set some value i.e.acct.email__c='abc@ss.com'Kindly mark this as a best answer if it helps you.Regards,Sagar@isTest
Public class getAccounts_Test{
public static testMethod void myTest(){
Account acc1 = new Account();
acc1.Name='acc1';
insert acc1;
getAccounts obj = new getAccounts();
Test.startTest();
String id = obj.getAccountRecords(acc1.id, 'XYZ');
System.assertEquals(id, acc1.id);
Test.stopTest();
}
}