You need to sign in to do that
Don't have an account?
Hoysala
Test class for this class please, anyone help
public class DS_ExpenseNoteTrigger_Handler { public static void checkExpenseNoteOverlapNew(list<DS_Expense_Note__c> listNewExpenseNotes){ Set<String> setExistingExpensePeriodId = new set<String>(); for(DS_Expense_Note__c thisExpense : [select Id,DS_Period_Information__c,CreatedbyId from DS_Expense_Note__c where CreatedbyId =:UserInfo.getUserId()]){ setExistingExpensePeriodId.add(thisExpense.DS_Period_Information__c); } for(DS_Expense_Note__c thisExpenseNote : listNewExpenseNotes){ if(setExistingExpensePeriodId.contains(thisExpenseNote.DS_Period_Information__c)){ thisExpenseNote.addError(Label.DS_ExpenseNote_Validation); } } } }
It will not give test failures in your test class and you can check for assertion using the SaveResult getErrors() methods
You can read more about here
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_database_saveresult.htm#apex_methods_system_database_saveresult
Hope this helps.
http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/
http://www.sfdcpoint.com/salesforce/test-class-with-example-salesforce/
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro