You need to sign in to do that
Don't have an account?
![Yumi Yumi](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Need Help with Apex Class
I am brand new to Apex and wrote my first trigger. a very simple one - and it works perfectly but a I'm not sure where to even start with writing an apex test class..
My trigger is setup to update a lookup field based on the value of another lookup field. (basically so the user can select the "account" from a record, hit save, and have the "parent account" automatically populate into the other lookup field. Rather than having to select a value for both lookup fields.)
Here is the trigger:
trigger UpdateManagementCompanyField on Transfer__c (before insert, before update) {for(Transfer__c a:Trigger.new){a.Management_Company__c = a.Management_Company_ID__c;}
}
Any help would be greatly appreciated!
Hi, YUMI
Try this.....!!
@isTest
private class TestTransferTrigger {
static testMethod void testcase1() {
Transfer__c objtra = new Transfer__c();
objtra.name = 'transfer1';
objtra.Management_Company_ID__c = 'Mgt-00001';
insert objtra;
}
}
Hope This Helps for you....!!!
Wow. Thank you Hitesh!!
:smileyhappy:
Hi Hitz,
I just started with APEX and VF.
i wrote the following trigger and am not able to write test class for that.
Can you please help me out with this??
TRIGGER
trigger increaseCount on Employee__c (after insert)
{
List<Employee__c> EmployeeToUpdate = new List<Employee__c>{};
for(Employee__c emp : Trigger.new)
{
Company__c company =[ select Number_of_Employees__c from Company__c where Id= :emp.Company__c ];
if (company.Number_of_Employees__c==Null)
{
company.Number_of_Employees__c=1;
}
else
{company.Number_of_Employees__c =company.Number_of_Employees__c+1;}
update company;
}
}
Hi,
just try to insert new record in your test class which satisfies your trigger code condition.
just follow below link
http://wiki.developerforce.com/index.php/How_to_Write_Good_Unit_Tests
@isTest
private class TestincreaseCountTrigger {
static testMethod void testcase1() {
// ToDo
---- your logic --- [insert new Employee]
}
}