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
GaneeeshGaneeesh 

Test class code coverage....

can anybody help me how can i cover this code...

 

public PageReference recedit() {
System.debug('*************************'+accid);
pagereference ref=new pagereference('/'+accid+'/e');
return ref;
}

 

 

and

 

public PageReference deleterec() {
Account acc=[select id,name from Account where id =: accid];
System.debug('***********************************'+acc);
delete acc;
pagereference ref=new pagereference('/apex/vieweditdelete');
ref.setredirect(true);
return ref;
}

Sneha PatilSneha Patil
Account acc = new Account(Name = 'Test Account');
insert acc;

ClassName objClass = new ClassName();
objClass.accid = acc.Id;

PageReference editRedirect = objClass.recedit();
system.assert(editRedirect.getUrl() == 
(new pagereference('/'+acc.Id+'/e')).getUrl());

PageReference delRedirect = objClass.deleterec();
list<Account> lstAcc = [select id,name from Account where id =: acc.Id];

system.assert(lstAcc.size() == 0);
system.assert(delRedirect.getUrl() == (new Pagereference('/apex/vieweditdelete').getUrl()));

 

Hope this helps !!

Please give KUDOS if this answer helped you :)