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

Help with the Test class for the following trigger.
Below trigger updates the Employee count under contact record whenever the employee count under Task it's task is updated.
Can anyone help me with the test class for this trigger? Thanks
trigger Update_employee_count_in_activity on Task (after insert, after update) { List<Contact> contsToUpdate = new List<Contact>(); Schema.DescribeSObjectResult r = Contact.sObjectType.getDescribe(); String keyPrefix = r.getKeyPrefix(); for(Task t:trigger.new){ String myIdPrefix = String.valueOf( t.WhoId).substring(0,3); if(myIdPrefix == keyPrefix){ Contact cont = new Contact(); cont.Id = t.WhoId; cont.Employees__c = t.FT_Emp__c; contsToUpdate.add(cont); } } if (contsToUpdate.size() > 0) { update contsToUpdate; } }
Can anyone help me with the test class for this trigger? Thanks
All Answers
At first Account record was missing. Then added new inserted new account as per Deepak's suggestion.
The system assert was failing.
Then changed the system assert as per RZ's suggestion. It worked.
Thanks you both.