You need to sign in to do that
Don't have an account?
SS Karthick
Regarding Testing
Hi folks,
Can anyone tell me how to test the following code:
public class CreateAccount{
Account[] a=new Account[3]
a[0]=new account (Name=Account1);
a[1]=new account (Name=Account2);
a[2]=new account (Name=Account3);
try{
Database.Insert(a,false);
}
catch(Exception e){
system.debug('Error Message:' +e.getMessage());
}
}
Thanks in advance
Karthick
Can anyone tell me how to test the following code:
public class CreateAccount{
Account[] a=new Account[3]
a[0]=new account (Name=Account1);
a[1]=new account (Name=Account2);
a[2]=new account (Name=Account3);
try{
Database.Insert(a,false);
}
catch(Exception e){
system.debug('Error Message:' +e.getMessage());
}
}
Thanks in advance
Karthick
I would also suggest you to go through this: https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank
All Answers
Hy Shashank_SFDC,
Lets consider this:
Trigger CreateContact Account (before insert){
Contact[] c=new contact[3];
for(Account a:trigger.new){
c[0]=new Contact(Account=a,LastName=lastname1);
c[1]=new Contact(Account=a,LastName=lastname2);
c[2]=new Contact(Account=a,LastName=lastname3);
}
try{
Database.Insert(c,false);
}
catch(Exception e){
system.debug('Error Message:' +e.getMessage());
}
}
For This how to write Positive Test and Negative Test???
Please Help!
________
Account[] a=new Account[3]
a[0]=new account (Name=Account1);
a[1]=new account (Name=Account2);
a[2]=new account (Name=Account3);
try{
Database.Insert(a,false);
}
catch(Exception e){
system.debug('Error Message:' +e.getMessage());
}
_________
in a method inside the class and call the function in a test class
something similar to :
http://salesforce.stackexchange.com/questions/36680/how-to-write-test-class-for-below-apex-class
I would also suggest you to go through this: https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
If this answers your question, please mark this as the Best Answer for this post, so that others can benefit from this post.
Thanks,
Shashank