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
alok7049alok7049 

Help with test case

controller method

.......................................

public class VfController{
                private final Contact con;
                
        public VfController(){
        con=[select id,name,Account.name,Account.id,Account.billingstreet from contact where id=:
           Apexpages.currentpage().getParameters().get('id')];
}
     public contact getCon(){
     return con;
     }
     public pageReference save(){
      update con;
      return null;
      }
      }

 

 

Ispita_NavatarIspita_Navatar

Hi,

Please find below the code for test method of your class:-

public class VfController
{
        private final Contact con;
        public VfController()
        {
        con=[select id,name,Account.name,Account.id,Account.billingstreet from contact where id=:
        Apexpages.currentpage().getParameters().get('id')];
        }
       public contact getCon()
       {
           return con;
       }
       public pageReference save()
       {
            update con;
            return null;
        }

       public static testMethod void testVfController()
                 {
        Account a1=new account(name='testaccount',billingstreet='street1');
        insert a1;
        Contact c1=new contact(firstname='f1',lastname='c1',accountid=a1.id);
       insert c1;
         ApexPages.CurrentPage().getParameters().put('id', c1.Id);
        VfController v1=new VfController();
        v1.getcon();
         v1.save();
    }

}

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.