You need to sign in to do that
Don't have an account?

How to write a test class for this apex classs
Hi Anyone help me how to write test class for this ?
Thanks in advance
public class theController { public List<Wrapper> contactList {get; set;} public static String mass {get;set;} public static boolean saveSuccessful {get; set;} public static string message {get; set;} ID Id = ApexPages.currentPage().getParameters().get('id'); public Integer offSetSize = 0; public Integer QueryLimit = 10; public Integer countTotalRecords{get;set;} public theController(ApexPages.StandardController controller){ countTotalRecords = [SELECT count() FROM Activity_Template__c WHERE For_Which_Object__c = 'Account']; } public List<Wrapper> getContacts() { if(contactList == null) { contactList = new List<Wrapper>(); for(Activity_Template__c c: [Select Name,Template_Tool_Tip__c,Template_Type__c FROM Activity_Template__c WHERE For_Which_Object__c = 'Account' LIMIT :QueryLimit OFFSET :offSetSize ]) { contactList.add(new Wrapper(c)); } } return contactList; } public boolean getprv(){ if(offSetSize > 0) return false; else return true; } public boolean getnxt(){ if(offSetSize + queryLimit < CountTotalRecords ) return false; else return true; } public PageReference nextbtn(){ contactList=null; offSetSize += queryLimit ; return null; } public PageReference prvbtn(){ contactList=null; offSetSize -= queryLimit ; return null; } public Integer getPageNumber() { return offSetSize/QueryLimit + 1; } public Integer getTotalPages() { if (math.mod(countTotalRecords, QueryLimit) > 0) { return countTotalRecords/QueryLimit + 1; } else { return (countTotalRecords/QueryLimit); } } public PageReference processSelected() { List<Activity_Template__c> selectedContacts = new List<Activity_Template__c>(); for(Wrapper cCon: getContacts()) { if(cCon.selected == true) { selectedContacts.add(cCon.con); } } for(Activity_Template__c con: selectedContacts) { system.debug(con); } // addParentAccount(id,selectedContacts); contactList=null; return null; } public class Wrapper { public Activity_Template__c con {get; set;} public Boolean selected {get; set;} public Wrapper(Activity_Template__c c) { con = c; selected = false; } } }
Thanks in advance
I went through the query of yours, Please go through these links :
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
https://developer.salesforce.com/forums/?id=9060G000000BgOWQA0
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Deepali Kulshrestha
Thanks for reply right now giving two errors:
Variable does not exist: exp
Variable does not exist: eli
ApexPages.StandardController sc = new ApexPages.StandardController(eli);
See in above line:
Test class line no 25 and 26.
Your code works awesome but can you help me in the negative testing part.
Please close this thread
https://trailhead.salesforce.com/en/content/learn/modules/unit-testing-on-the-lightning-platform/negative-tests