You need to sign in to do that
Don't have an account?
Rahul
Hi can someone help me complete this Test class. Iam getting only 25% code overage. Thanks
Apex class :
trigger updatePhoneAndEmailOnAcc on Contact (after update) {
map<id,contact> accidVSContact = new map<id, contact>();
for(contact c1: trigger.new) {
if(Trigger.newMap.get(c1.id).Email != Trigger.oldMap.get(c1.id).Email ||
Trigger.newMap.get(c1.id).MobilePhone != Trigger.oldMap.get(c1.id).MobilePhone) {
accidVSContact.put(c1.AccountId, c1);
}
}
system.debug('accidVSContact:::'+accidVSContact);
List<account> accls = [select id, Created_By_Email__c, Mobile_Number__c from account where id IN :accidVSContact.keySet()];
system.debug('accls:::'+accls);
for(account a1 :accls) {
a1.Created_By_Email__c = accidVSContact.get(a1.id).Email;
system.debug('a1.Created_By_Email__c:::'+a1.Created_By_Email__c);
system.debug('accidVSContact.get(a1.id).Email:::'+accidVSContact.get(a1.id).Email);
a1.Mobile_Number__c = accidVSContact.get(a1.id).MobilePhone ;
system.debug('a1.Mobile_Number__c:::'+a1.Mobile_Number__c);
system.debug('accidVSContact.get(a1.id).MobilePhone:::'+accidVSContact.get(a1.id).MobilePhone);
}
system.debug('accls:::'+accls);
//&& !trigger.isExecuting
if(accls.size()>0) {
system.debug('herrer!!!!');
try {
update accls;
} catch(exception e) {system.debug('error::'+e);}
system.debug('accls!!!'+accls);
}
Test class:
@istest
public class updatePhoneAndEmailOnAcc_test{
static testmethod void mm(){
Account ac = new Account (Name = 'Test Account123_1', Campaigner_Name__c = 'Ab_c12',Created_By_Email__c='test@abc.com',Mobile_Number__c ='9999999999');
insert ac;
Contact contact = new Contact (FirstName = 'Test', LastName = 'Contact');
contact.accountid =ac.id;
insert contact;
list<account> aa =[select id,Created_By_Email__c from account where id =: ac.id];
}
}
trigger updatePhoneAndEmailOnAcc on Contact (after update) {
map<id,contact> accidVSContact = new map<id, contact>();
for(contact c1: trigger.new) {
if(Trigger.newMap.get(c1.id).Email != Trigger.oldMap.get(c1.id).Email ||
Trigger.newMap.get(c1.id).MobilePhone != Trigger.oldMap.get(c1.id).MobilePhone) {
accidVSContact.put(c1.AccountId, c1);
}
}
system.debug('accidVSContact:::'+accidVSContact);
List<account> accls = [select id, Created_By_Email__c, Mobile_Number__c from account where id IN :accidVSContact.keySet()];
system.debug('accls:::'+accls);
for(account a1 :accls) {
a1.Created_By_Email__c = accidVSContact.get(a1.id).Email;
system.debug('a1.Created_By_Email__c:::'+a1.Created_By_Email__c);
system.debug('accidVSContact.get(a1.id).Email:::'+accidVSContact.get(a1.id).Email);
a1.Mobile_Number__c = accidVSContact.get(a1.id).MobilePhone ;
system.debug('a1.Mobile_Number__c:::'+a1.Mobile_Number__c);
system.debug('accidVSContact.get(a1.id).MobilePhone:::'+accidVSContact.get(a1.id).MobilePhone);
}
system.debug('accls:::'+accls);
//&& !trigger.isExecuting
if(accls.size()>0) {
system.debug('herrer!!!!');
try {
update accls;
} catch(exception e) {system.debug('error::'+e);}
system.debug('accls!!!'+accls);
}
Test class:
@istest
public class updatePhoneAndEmailOnAcc_test{
static testmethod void mm(){
Account ac = new Account (Name = 'Test Account123_1', Campaigner_Name__c = 'Ab_c12',Created_By_Email__c='test@abc.com',Mobile_Number__c ='9999999999');
insert ac;
Contact contact = new Contact (FirstName = 'Test', LastName = 'Contact');
contact.accountid =ac.id;
insert contact;
list<account> aa =[select id,Created_By_Email__c from account where id =: ac.id];
}
}
All Answers