You need to sign in to do that
Don't have an account?

how can i write test method delete event?
I write a test method for below class code coverage is 60% can any body tell how can i write a testmethod for the delete event...
Class TestMethod
@isTest
private class testparamcls{
static testmethod void method(){
paramcls obj=new paramcls();
obj.delrec();
}
}
Class
public with sharing class paramcls {
public PageReference delrec() {
System.debug('----------------RecordId---------------'+recordId);
Account acc = [Select id from account where id=:recordId];
delete acc;
pagereference ref = new pagereference('/apex/param');
ref.setredirect(true);
return ref;
}
public string recordId{get; set;}
public List<Account> lst {get; set;}
public paramcls(){
lst = [Select id, name, phone from Account];
}
}
Hi,
Try the below code snippet as reference:
@isTest
private class testparamcls{
static testmethod void method(){
paramcls obj=new paramcls();
Account acc=new Account();
acc.name='test';
insert acc;
obj.recordId=acc.id;
obj.delrec();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
Hi,
Try the below code snippet as reference:
@isTest
private class testparamcls{
static testmethod void method(){
paramcls obj=new paramcls();
Account acc=new Account();
acc.name='test';
insert acc;
obj.recordId=acc.id;
obj.delrec();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Hi Navatar,
Thank you .Please let me know for where can get the best practices for the apex code development &Visualforce