You need to sign in to do that
Don't have an account?
srikanth kambampati 6
Help me to write the test class for the below code.
Hi, i wrote one trigger on account object, when even an account is created automatically create a contact for that account. And my trigger is
trigger acc_con on Account (after insert) {
List<Contact> cons = new List<Contact>();
for(Account a:trigger.new) {
Contact c =new Contact();
c.lastName = a.Name;
c.Phone = a.phone;
c.AccountId = a.id;
cons.add(c);
}
insert cons;
}
trigger acc_con on Account (after insert) {
List<Contact> cons = new List<Contact>();
for(Account a:trigger.new) {
Contact c =new Contact();
c.lastName = a.Name;
c.Phone = a.phone;
c.AccountId = a.id;
cons.add(c);
}
insert cons;
}
All Answers
Please find the below code:
can you please let me know if it helps or not.
if it helps don't forget to mark as best answer.
Thanks,
Balaji J
How to write test class. You can learn from given below URL.
I hope you understand this.
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
https://trailhead.salesforce.com/en/modules/apex_testing/units/apex_testing_intro
//100% code coverage
@isTest
private class AccountTrigger_Test {
static testmethod void testEx2(){
Account a = new Account();
a.Name = 'Test';
a.Phone ='12345';
Test.startTest();
insert a;
Test.stopTest();
}
}
Please mark it as best Answer if you find it helpful.
Thank You
Ajay Dubedi
thanks to all for giving reply to my question and all are giving 100% code coverage.
Thanks & regards
srikanth k