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

hi guys can you guys suggest me the proper way of writing the test class for this trigger
trigger beins_duplicate on Account (after insert) {
account na = trigger.new[0];
contact c=new contact();
c.lastname=na.name;
c.phone=na.phone;
c.accountid=na.id;
insert c;
opportunity o=new opportunity();
o.Name = na.Name;
o.CloseDate = date.today();
o.StageName = 'Prospecting';
o.accountid=na.id;
insert o;
}
nd i had written the test class as
------------------
@istest
public class benis_duplicatetest
{
static testmethod void test1(){
account ac=new account(name='hari', phone='9700956194');
/* ac.name='hari';
ac.phone='9700956194';
*/
insert ac;
contact co =new contact();
co.accountId=ac.Id;
co.lastname=ac.name;
co.phone=ac.phone;
insert co;
system.AssertEquals('hari',co.lastname);
system.AssertEquals('9700956194',co.phone);
}
}
account na = trigger.new[0];
contact c=new contact();
c.lastname=na.name;
c.phone=na.phone;
c.accountid=na.id;
insert c;
opportunity o=new opportunity();
o.Name = na.Name;
o.CloseDate = date.today();
o.StageName = 'Prospecting';
o.accountid=na.id;
insert o;
}
nd i had written the test class as
------------------
@istest
public class benis_duplicatetest
{
static testmethod void test1(){
account ac=new account(name='hari', phone='9700956194');
/* ac.name='hari';
ac.phone='9700956194';
*/
insert ac;
contact co =new contact();
co.accountId=ac.Id;
co.lastname=ac.name;
co.phone=ac.phone;
insert co;
system.AssertEquals('hari',co.lastname);
system.AssertEquals('9700956194',co.phone);
}
}
P.s. Did not compile this but should work. Let me know if there are any compile errors.
Mark as answered if works.
Cheers,
Siddhesh Kabe
Sforce.Ninja
All Answers
Check the below link.
https://developer.salesforce.com/page/How_to_Write_Good_Unit_Tests
https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
P.s. Did not compile this but should work. Let me know if there are any compile errors.
Mark as answered if works.
Cheers,
Siddhesh Kabe
Sforce.Ninja