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

Apex trigger & test help please
Hi,
I've written a very simple Apex Trigger (My first).
it aims to count the number of Timesheet__c records with a given date, and update these to another object called Week__c.
I cannot seem to deploy this trigger. due to Test coverage being insufficiet (0%). and due to average Apex test coverage, which i is 50% (as opposed to the required 75%).
Thanks so much.
Ben
I've written a very simple Apex Trigger (My first).
it aims to count the number of Timesheet__c records with a given date, and update these to another object called Week__c.
I cannot seem to deploy this trigger. due to Test coverage being insufficiet (0%). and due to average Apex test coverage, which i is 50% (as opposed to the required 75%).
- Please help me understand what would be a test method for this trigger.
- Where would I write this method (in the apex trigger code? after the closing bracket?
Code:
trigger Timesheets_Count on Week__c (after insert, after update, after delete, after undelete) { Date weekending = Trigger.new[0].Week_Ending__c; Week__c my_week = [select w.id, w.Number_Of_Timesheets__c from Week__c w WHERE w.Week_Ending__c = :weekending limit 1]; Integer number_of_sheets = [select COUNT() from Timesheet__c t where t.Week_Ending__c =:weekending]; my_week.Number_Of_Timesheets__c = number_of_sheets; //update My_week;// is this Line needed at all
}
Thanks so much.
Ben
Then during deployment, include the trigger and the apex class (that contains the test methods).