I am new to Salesforce. I have written a trigger to update contact based on account field .The Trigger code is below.
trigger Update_contact_based_on_acc on Account (before update) {
List<contact> cont = new List<contact>();
for(Account acc : Trigger.new){
if(acc.Type == 'Prospect'){
Contact con = new contact();
con.AccountId = acc.Id;
con.FirstName = acc.Name;
con.LastName = acc.Phone;
cont.add(con);
}
}
if(cont.size()>0){
insert cont;
}
}
I want to use System.assert,System.AssertEquals,Test.start,test.stop and system.runas
to clear my concept.So how can I use these in my test class which is attached below
@isTest
public class Update_contact_based_on_accTest {
public static testmethod void PrimaryAccountTest(){
Account acc = new Account();
acc.Name = 'Test';
acc.Type = 'Prospect';
insert acc;
acc.Phone = '8404868903';
update acc;
contact con = new contact(FirstName='accnmame',LastName='test',
AccountId=acc.Id);
insert con;
system.assertEquals(expected, actual);
}
}