You need to sign in to do that
Don't have an account?
SFDC12
help for testclass scenario
Hi everyone,
Below trigger and testclass ,trigger working fine ,there is no code coverage for the trigger,what am missing in testclass,can someone plz help me out.
Trigger,
trigger updatephonebasedonaddress1 on Account (after update) {
List<contact>conlist=new List<contact>();
set<Id>accid=new set<id>();
for(Account a:trigger.new){
accid.add(a.id);
}
List<Account>acclist=[select id,name,phone,BillingCountry,(select id,Phone,LastName,MailingCountry from contacts)from Account where id=:accid];
for(Account a:acclist){
for(contact c:a.contacts){
if(c.MailingCountry==a.BillingCountry){
c.phone=a.phone;
conlist.add(c);
}
}
update conlist;
}
}
Testclass:
@isTest
public class Testupdatephonebasedonaddress1 {
@isTest
static void clme(){
Account a=new Account();
a.Name='test';
a.BillingCountry='inr';
a.Phone='2328938';
insert a;
Contact c=new Contact();
c.LastName='conname';
c.MailingCountry='inr';
c.AccountId=a.Id;
insert c;
Test.startTest();
List<Contact> con=[select id,name,phone from Contact where Accountid=:a.Id];
con[0].phone=a.Phone;
update con;
Test.stopTest();
}
}
Below trigger and testclass ,trigger working fine ,there is no code coverage for the trigger,what am missing in testclass,can someone plz help me out.
Trigger,
trigger updatephonebasedonaddress1 on Account (after update) {
List<contact>conlist=new List<contact>();
set<Id>accid=new set<id>();
for(Account a:trigger.new){
accid.add(a.id);
}
List<Account>acclist=[select id,name,phone,BillingCountry,(select id,Phone,LastName,MailingCountry from contacts)from Account where id=:accid];
for(Account a:acclist){
for(contact c:a.contacts){
if(c.MailingCountry==a.BillingCountry){
c.phone=a.phone;
conlist.add(c);
}
}
update conlist;
}
}
Testclass:
@isTest
public class Testupdatephonebasedonaddress1 {
@isTest
static void clme(){
Account a=new Account();
a.Name='test';
a.BillingCountry='inr';
a.Phone='2328938';
insert a;
Contact c=new Contact();
c.LastName='conname';
c.MailingCountry='inr';
c.AccountId=a.Id;
insert c;
Test.startTest();
List<Contact> con=[select id,name,phone from Contact where Accountid=:a.Id];
con[0].phone=a.Phone;
update con;
Test.stopTest();
}
}
Trigger Is Working If Account BillingCountry And Contact MailingCountry Are Same then update Contact phone With Account Phone okay Please Close Your Query By Marking It As Best Answer If It Helps
Thank You!
All Answers
Try Below Test Class Please Mark It As Best Answer If It Helps
Thank You!
Trigger Is Working If Account BillingCountry And Contact MailingCountry Are Same then update Contact phone With Account Phone okay Please Close Your Query By Marking It As Best Answer If It Helps
Thank You!