You need to sign in to do that
Don't have an account?
Help required for @TestClass
Hi,
i have this trigger (worked fine) - but i cant figure out how to create a testclass to go with it. Can anyone help me please?
this trigger is update Account object (custom lookup field - Related_Contract_Number__c) with the contractnumber from the Contract object when few criteria will change.
Here is my trigger (worked fine) - it does seems to work but i cant get the testmethod.
trigger ContractNumUpdate on Contract (after update) {
List<ID> AccIds = New List<ID>();
for(Contract c : Trigger.new)
{
if(c.Status == 'Act' && c.Type__c == 'MS' && c.ContractNumber !=null)
{
AccIds.add(c.AccountId);
}
}
List<Account> accList = [Select Id, Related_Contract_Number__c from Account where Id in :AccIds];
Map<id,Contract>accContract = New Map<id,Contract>();
for (Contract con : Trigger.new)
{
accContract.put(con.AccountId,con);
}
for(integer i=0; i < accList.size(); i++)
{
accList[i].Related_Contract_Number__c = accContract.get(accList[i].Id).Id;
}
update accList;
}
can u plz tell that wat prob u r facing?
My prob is how to write a test class for above trigger. Any help would be appriciated!
do u know how to write test classes?
I dont. Any help
you can get the help from here
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_example.htm
and
http://wiki.developerforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
Thanks for this info. I will give it a go but on initial stage it's bit difficulte for me to implement the test class for above trigger as i am a newbie. Can you help for the soluation at this stage?
Thanks for all your help!
Create simple test class. in test method create Contact and then update it. trigger will fire so tested.
You don't know how to write tests in general?
Write next code in test method of test class:
Thanks Chiz,
Do i alos need to create Account?
When you will run this particular test it would fire exception with text. This text will contain all necessary fields for Contract. Sorry, I don't know must fields for Contract sObject. It will be your challenge ;)
I am having a hard time to write a test class for this trigger.
here is a trigger (works fine)
I have started writing a test class but stuck at end of the code and dont know how to evaluate futher??? can someone help me here to complete the test class?
thanks in advaced!
There is no need to assert something. Trigger will fire and you will have code coverage.