You need to sign in to do that
Don't have an account?
TC Admin
Help writing Test class code for SOQL and override save button
Hi, I'm struggling to write a test class that has over 75% code coverage. I currently only have 57% since adding an override to the save button.
Before the save button I have 82%.
I thought I just needed to add the save method to the class but obviously not. Any help would be hugly welcome.
APEX CLASS CONTROLLER
TEST CLASS
Before the save button I have 82%.
I thought I just needed to add the save method to the class but obviously not. Any help would be hugly welcome.
APEX CLASS CONTROLLER
PUBLIC CLASS TimeSheetEditAllItemsList { PUBLIC LIST <Time_sheet_items__c> GetItemsList {get;set;} PUBLIC TimeSheetEditAllItemsList(ApexPages.StandardController ctrl){ GetItemsList = [ SELECT Id,Time_Sheet__c,D_Product_Manager__c,D_Type__c,D_Project__c,Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c, Day_Thursday__c,Day_Friday__c,Day_Weekend__c,Day_Monday_Comment__c,Day_Tuesday_Comment__c,Day_Wednesday_comment__c,Day_Thursday_Comment__c,Day_Friday_Comment__c,Day_Weekend_Comment__c FROM Time_Sheet_Items__c WHERE Time_Sheet__c= : ctrl.getId() ORDER BY id ASC ]; } public pageReference save(){ UPSERT GetItemsList ; return null; } }
TEST CLASS
@isTest Private class TestClassTimeSheetEditAllItemsList { static testMethod void GetItemsList() { // create new TS record to test against Time_Sheet__C TS = new Time_Sheet__c(); TS.Time_sheet_week_ending__C = date.Newinstance (2016,06,06); TS.Employee__C ='a0Gb000000Cm6OHEAZ'; insert TS; // create a line item for the TS to test against Time_Sheet_Items__c TSi = new TIme_Sheet_Items__c(); TSi.D_project__C ='011 GFX'; TSi.D_Type__c = '05 Editorial'; TSi.Time_Sheet__c =TS.Id; TSi.RecordTypeid ='012b00000009cosAAA'; insert TSi; // Construct the standard controller ApexPages.StandardController con = new ApexPages.StandardController(TS); // create the controller TimeSheetEditAllItemsList ext = new TimeSheetEditAllItemsList(con); //Start the test Test.startTest(); // Check that Time sheets created and can query data with items lines Time_Sheet_Items__c TSiL=[ SELECT Id,Time_Sheet__c,Day_Monday__c,Day_Tuesday__c,Day_Wednesday__c,Day_Thursday__c,Day_Friday__c,Day_Weekend__c,Day_Monday_Comment__c,Day_Tuesday_Comment__c,Day_Wednesday_comment__c,Day_Thursday_Comment__c,Day_Friday_Comment__c,Day_Weekend_Comment__c FROM Time_Sheet_Items__c ]; // Check the save works con.save(); // Check it ran System.assert(TSiL!=null); // Stop test Test.stopTest(); } }
Hi,
Greetings to you! It is a pleasure to be in touch with you again.
You need to use ext.save(); instead of con.save(); because ext is instance of class.
Try below code:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas
All Answers
Hi,
Greetings to you! It is a pleasure to be in touch with you again.
You need to use ext.save(); instead of con.save(); because ext is instance of class.
Try below code:
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas