You need to sign in to do that
Don't have an account?
Matt Lim 7
Create identical contacts upon account creation
I am trying to create two identical contacts upon account creation. so far i have written below :
trigger IdenticalContacts on Account (after insert) {
for (Account acc : Trigger.new){
Contact con = new Contact();
con.LastName = 'Monkey D';
con.FirstName = 'Luffy';
con.email = 'goldroger@gmail.com';
con.AccountId = acc.id;
}
}
I also wrote test class below but getting 0% code coverage:
@isTest
public class TestIndenticalContacts {
@isTest static void createAccount(){
Account acc = new Account();
acc.Name = 'Salesforce';
insert acc;
}
}
Is the problem due to 'After Insert'?
trigger IdenticalContacts on Account (after insert) {
for (Account acc : Trigger.new){
Contact con = new Contact();
con.LastName = 'Monkey D';
con.FirstName = 'Luffy';
con.email = 'goldroger@gmail.com';
con.AccountId = acc.id;
}
}
I also wrote test class below but getting 0% code coverage:
@isTest
public class TestIndenticalContacts {
@isTest static void createAccount(){
Account acc = new Account();
acc.Name = 'Salesforce';
insert acc;
}
}
Is the problem due to 'After Insert'?
you forgot to insert contact.
try below code. Test class now try below code. I believe it will help you.
Make sure your trigger is Active.
don't forget to mark it as best answer.
Thank you
All Answers
How are you checking the code coverage, I would suggest to use developer console to check the coverage.
If still you are not able to cover the code please check that your trigger is active.
you forgot to insert contact.
try below code. Test class now try below code. I believe it will help you.
Make sure your trigger is Active.
don't forget to mark it as best answer.
Thank you
did you try above code. try it once and let me know and don't forget to mark it as best answer.
Your one best mark give us motivation to working in this direction.
Thank you