You need to sign in to do that
Don't have an account?
asims2006
Trigger Create test class
I've created the trigger below and now i'm having issues creating a test class. Can someone please help? trigger Parent_Name_Trigger on Account (after insert) { List sr = new List(); for (Account newAccount: Trigger.New) if (newAccount.Student_Name__c <> ''){ sr.add (new Student__c( Account__c = newAccount.ID, Name = newAccount.Student_Name__c)) ; } insert sr; }
All Answers
First, I suggest you edit your post and copy/paste the code text into the "insert code" popup you can access for the text editing toolbar. Makes it easier for us to read!
This is the code text you posted:
I notice your for clause is missing its { }'s.
Question: is Student_Name__c a lookup field pointing to a contact record? Or is it just a text field?
What exactly would you like help with on your test class? Broad strokes would be to create a test class that creates an account with student_name__c populated, then make a system assertion that the newly inserted student record has that account as it's parent.
This worked Perfect! I appreciate your help. I'm new to working with Apex I'll be descriptive in my next posts.
Public class ParentNameTriggerTest
{
Public static testMethod void AccountTest()
{
Account acc=new Account();
acc.Name='Example';
acc.Student_Name__c='Asim';
insert acc;
Student__c stu=new Student__c();
stu.Account__c=acc.Id;
stu.Student_Name__c=acc.Student_Name__c;
insert stu;
}
}