You need to sign in to do that
Don't have an account?
Narcissu
Test Methods for this code
Can anyone give me some ideas how and where to write a test method for the following code? Much thanks.
trigger Caseupdate on Case(after insert)
{
Case b = new Case();
Set<id> AccountIDs = new set<id>();
list<Account> AcctList = new list<Account>();
for(case c : Trigger.new)
{
for(Account at:[Select id,Last_Update__c From Account where id =: c.accountid])
{
at.Last_Update__c = date.valueof(c.createddate);
AcctList.add(at);
}
}
update AcctList;
}
Hi,
Try the below code for reference of test method:
@isTest
private class testTriggerinsert_Contact_ActivityTest0
{
public static testMethod void unitTestinsert_Contact_Activity4Task()
{
account ac=new account(name='test');
insert ac;
case c=new case(status='abc',accountid=ac.id);
insert c;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
There's no need to create the new Case "b"
Take your query out of the loop, if possible.
To test, create a bunch of Accounts. In a loop, instantiate 200 Cases, with a randomly assigned Account from what you created. Insert the list of 200 Cases.
Thank you for your reply and correction!
Sorry but I don't quite understand the test part, can you write it in a code format?
Hi Narcissu,
U just create case object and insert the some fields and update them in the same way for Account also
let me know if any issue regarding thi.
Regards
SRS
Hi,
Try the below code for reference of test method:
@isTest
private class testTriggerinsert_Contact_ActivityTest0
{
public static testMethod void unitTestinsert_Contact_Activity4Task()
{
account ac=new account(name='test');
insert ac;
case c=new case(status='abc',accountid=ac.id);
insert c;
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Thanks all. The code from DbSup gives me a 100% code coverage for my code above.