function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sandeepathadusandeepathadu 

help for test case

plz help me how to write test case for my trigger

trigger Dev_update_Appt on Appointment__c(after update)
{
public list<appointment__c> apps {get;set;}  
public list<appointment__c> apps5 {get;set;} 
apps5 = new list<appointment__c>();
apps = new list<appointment__c>();

Map<ID , appointment__c> mapAppiontment = new MAP<ID , appointment__c>([select ID,Account__c,Name,Branch__c,Doctor__c,Appt_Date__c, Dev_Parent_Appt__c from appointment__c where 

id in: trigger.old]);

List<appointment__c> listApp = new List<appointment__c>();

MAP<ID , List<appointment__c>> mapAPPID_List = new MAP<ID , List<appointment__c>>();
for(appointment__c appObj : [select ID,Account__c,Name,Branch__c,Doctor__c,Appt_Date__c,Dev_Parent_Appt__c from appointment__c where   Dev_Parent_Appt__c in: 

mapAppiontment.keyset()])
{
  if(mapAPPID_List.containskey(appObj.Dev_Parent_Appt__c))
     {
         listApp = mapAPPID_List.get(appObj.Dev_Parent_Appt__c);
     }
   else
     {
        listApp = new List<appointment__c>();
     }
  
  listApp.add(appObj);
  mapAPPID_List.put(appObj.Dev_Parent_Appt__c , listApp);

}

for(Appointment__c o:Trigger.old )
{   

if (Trigger.isUpdate)
{
appointment__c  app1 = mapAppiontment.get(o.id);
List<appointment__c>  app  = new List<appointment__c>();

if(mapAPPID_List.containsKey(app1.id))
   app = mapAPPID_List.get(app1.id);

for(appointment__c ap:app)
{
ap.branch__c=app1.branch__c;
ap.Doctor__c=app1.Doctor__c;
ap.Appt_Date__c=app1.Appt_Date__c; 
apps.add(ap);
}
} 
}
update apps;
}

 my test case i have written i am getting 60 percent 

@isTest
private class updateclass
{

static testmethod void TestController() 
{

Staff__c s1 = new Staff__c();
      s1.name='Rahul';
      s1.Mobile__c='9849098490';
      insert s1;


Branch__c b = new Branch__c();
b.Name = 'Test';
b.Region__c = 'Market Price';
insert b;


Account a = new Account ();
a.LastName = 'Test';
a.Branch__c = b.id;
a.PersonMobilePhone = '9550412970';
insert a ;







    Appointment__c app2 = new Appointment__c();
      app2.account__c=a.id;
      
      //app2.Dev_Parent_Appt__c=app1.id;
      
      
         app2.from__c='6';
        
        app2.from_min__c = '00';
        app2.Appt_AM_PM__c='PM';
        app2.Appt_Date__c=date.ValueOf('2011-05-21');
        app2.Appt_Hour__c='9';
        app2.Appt_Minute__c='80';
        app2.RecordTypeid='012N0000000CgZ2';
       
        app2.Branch__c=b.id;
        app2.to_Min__c='40';
        app2.to__c='7';
          insert app2;
       update app2 ;
       
      
       }
       }

 plz help me to resolve my issue

Best Answer chosen by Admin (Salesforce Developers) 
Shashikant SharmaShashikant Sharma

Hi,

 

I remember this trigger.

 

Let me try with test class as well

 

@isTest
private class updateclass
{

static testmethod void TestController() 
{

Staff__c s1 = new Staff__c();
      s1.name='Rahul';
      s1.Mobile__c='9849098490';
      insert s1;


Branch__c b = new Branch__c();
b.Name = 'Test';
b.Region__c = 'Market Price';
insert b;


Account a = new Account ();
a.LastName = 'Test';
a.Branch__c = b.id;
a.PersonMobilePhone = '9550412970';
insert a ;







    Appointment__c app2 = new Appointment__c();
      app2.account__c=a.id;
      
         app2.from__c='6';
        
        app2.from_min__c = '00';
        app2.Appt_AM_PM__c='PM';
        app2.Appt_Date__c=date.ValueOf('2011-05-21');
        app2.Appt_Hour__c='9';
        app2.Appt_Minute__c='80';
        app2.RecordTypeid='012N0000000CgZ2';
       
        app2.Branch__c=b.id;
        app2.to_Min__c='40';
        app2.to__c='7';
          insert app2;

        
      Appointment__c app1 = new Appointment__c();
      app1.account__c=a.id;
      
      app1.Dev_Parent_Appt__c=app2.id;
      
      
         app1.from__c='6';
        
        app1.from_min__c = '00';
        app1.Appt_AM_PM__c='PM';
        app1.Appt_Date__c=date.ValueOf('2011-05-21');
        app1.Appt_Hour__c='9';
        app1.Appt_Minute__c='80';
        app1.RecordTypeid='012N0000000CgZ2';
       
        app1.Branch__c=b.id;
        app1.to_Min__c='40';
        app1.to__c='7';
        insert app1;
       
        update app2 ;
        
       }
}

 

All Answers

Shashikant SharmaShashikant Sharma

Hi,

 

I remember this trigger.

 

Let me try with test class as well

 

@isTest
private class updateclass
{

static testmethod void TestController() 
{

Staff__c s1 = new Staff__c();
      s1.name='Rahul';
      s1.Mobile__c='9849098490';
      insert s1;


Branch__c b = new Branch__c();
b.Name = 'Test';
b.Region__c = 'Market Price';
insert b;


Account a = new Account ();
a.LastName = 'Test';
a.Branch__c = b.id;
a.PersonMobilePhone = '9550412970';
insert a ;







    Appointment__c app2 = new Appointment__c();
      app2.account__c=a.id;
      
         app2.from__c='6';
        
        app2.from_min__c = '00';
        app2.Appt_AM_PM__c='PM';
        app2.Appt_Date__c=date.ValueOf('2011-05-21');
        app2.Appt_Hour__c='9';
        app2.Appt_Minute__c='80';
        app2.RecordTypeid='012N0000000CgZ2';
       
        app2.Branch__c=b.id;
        app2.to_Min__c='40';
        app2.to__c='7';
          insert app2;

        
      Appointment__c app1 = new Appointment__c();
      app1.account__c=a.id;
      
      app1.Dev_Parent_Appt__c=app2.id;
      
      
         app1.from__c='6';
        
        app1.from_min__c = '00';
        app1.Appt_AM_PM__c='PM';
        app1.Appt_Date__c=date.ValueOf('2011-05-21');
        app1.Appt_Hour__c='9';
        app1.Appt_Minute__c='80';
        app1.RecordTypeid='012N0000000CgZ2';
       
        app1.Branch__c=b.id;
        app1.to_Min__c='40';
        app1.to__c='7';
        insert app1;
       
        update app2 ;
        
       }
}

 

This was selected as the best answer
sandeepathadusandeepathadu

thank u once again i have live now 

sandeepathadusandeepathadu

i have seen u r blog it is really usefull for developers like me plz keep doing many more like these which will help us very much 

 

thank you sir

 

with regards 

 

 

sandeep sharma

Shashikant SharmaShashikant Sharma

Your welcome sandeep