You need to sign in to do that
Don't have an account?
Chad Moutes
Need Help With Test Class
Okay so I have a Trigger that fires after insert of Task. The Trigger works perfectly, I wrote the following Test Class and I'm only getting 75% code Coverage and I need more than that because my org average is only at 57%. Any help would be greatly appreciated.
@isTest public class TestTaskCreationAccount { static testMethod void insertNewTask() { Task taskToCreate = new Task(); taskToCreate.OwnerId = '005i0000004N77x'; taskToCreate.Subject = 'Attempted Call'; taskToCreate.Status = 'Completed'; insert taskToCreate; taskToCreate = [SELECT Status From Task WHERE Id =:taskToCreate.Id]; System.debug('Status after trigger fired: ' + taskToCreate.Status); System.assertEquals('Completed', taskToCreate.Status); delete taskToCreate; } }
1) Insert a Recruit__c record first with test data, some thing like:
Recruit__c recruit_Record=new (Name='Something',.....);
insert recruit_Record;
2) Create a task using the id from above statement.,
Task Task_Record=new Task(Status='Completed', Subject='Email Sent',WhatId=recruit_Record.id); // In the query from trigger you were querying only the task records which have subject as email sent or email received.
insert Task_Record;
3) Delete the task record.
Try it!
And instead of hardcoding the task owner you could insert an user an use his id instead as a best practice.
For more info visit:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_tools_runas.htm
Thanks,
Balaji
All Answers
@Chad Moutes:
If you can post your trigger code, it will he helpful in guiding the right way!
Thanks,
balaji
1) Insert a Recruit__c record first with test data, some thing like:
Recruit__c recruit_Record=new (Name='Something',.....);
insert recruit_Record;
2) Create a task using the id from above statement.,
Task Task_Record=new Task(Status='Completed', Subject='Email Sent',WhatId=recruit_Record.id); // In the query from trigger you were querying only the task records which have subject as email sent or email received.
insert Task_Record;
3) Delete the task record.
Try it!
And instead of hardcoding the task owner you could insert an user an use his id instead as a best practice.
For more info visit:
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_tools_runas.htm
Thanks,
Balaji
Error Message System.StringException: Invalid id: R.Id
Stack Trace Class.TestTaskCreationRecruit.insertNewTask: line 19, column 1
https://developer.salesforce.com/forums/#!/feedtype=SINGLE_QUESTION_DETAIL&dc=Apex_Code_Development&criteria=OPENQUESTIONS&id=906F0000000AyN4IAK
Cheers.,