You need to sign in to do that
Don't have an account?
srikanth cheera 6
Any one can write test code for this
Any one can write test code for this
=============================
public class Task04{
public static void beforeinsert(list<Opportunity> opo){
for(Opportunity op:opo){
if(op.name!=null){
op.stagename='prospecting';
op.closedate=system.today()+15;
}
}
}
}
====
Thanks
=============================
public class Task04{
public static void beforeinsert(list<Opportunity> opo){
for(Opportunity op:opo){
if(op.name!=null){
op.stagename='prospecting';
op.closedate=system.today()+15;
}
}
}
}
====
Thanks
You can use this code for your test class
If it helps you, Kindly mark this answer as best, so that it will be removed from unsolved qestions
Regards
Suraj
But it is working fine with 100% coverage in my org
Make Sure You are checking coverage for your trigger and its handler, not for test class itself.
You can run your test class from here, but for coverage, we always check coverage on Main Class and Trigger Code
You can see here my Apex Class and Trigger both are covered with 100% code coverage
//Trigger_Handler is covering with 100% coverage, you can check it.
//Trigger is also covered with 100% coverage
Now, if you have any doubt, please feel free to ask me
Regards
Suraj
====================
public class Task14 {
public static void beforeupdate(Map<id,Account> oldmap,Map<id,Account> newmap){
list<id> accid=new list<id>();
for(id key:oldmap.keySet()){
Account old=oldmap.get(key);
Account newmp=newmap.get(key);
if(old.Phone!=newmp.Phone){
accid.add(key);
}
}
list<Contact> con=[select lastname,firstname,phone,accountid from Contact where accountid in:accid];
for(Contact c:con){
Account a=newmap.get(c.accountid);
Account b=oldmap.get(c.accountid);
c.Phone=a.Phone;
c.OtherPhone=b.phone;
}
update con;
}
}
==========================================================
trigger Task14Trigger on Account (before update) {
if(trigger.isbefore && trigger.isupdate){
Task14.beforeupdate(Trigger.oldmap, Trigger.newmap);
}
}
====================================================================
@istest
private class Task14Test {
@istest static void test(){
Account acc=new Account();
acc.name='sree';
acc.Phone='7569';
test.startTest();
Task14 ta=new Task14();
insert acc;
test.stopTest();
Contact con=new Contact();
con.lastname='eers';
con.Phone='7569';
con.OtherPhone='123';
con.AccountId=acc.id;
acc.phone='456';
test.startTest();
update acc;
test.stoptest();
system.assertEquals(acc.phone, con.phone);
system.assertEquals(acc.phone, con.OtherPhone);
}
}
==================================================
This is test class for your second code
with 100% coverage
If this resolve your problem, then kindly please mark this answer as best answer,
Regards
Suraj