You need to sign in to do that
Don't have an account?
![Shreyanka Shreyanka](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Test class for the below apex class
Hi everyone,
Please help me in writting test class for the below apex code:
public class xyz {
public abc objabc{get;set;}
public Boolean sendEmail {get; set;}
public Task objtask{get;set;}
public boolean isChecked{get;set;}
public xyz() {
String objabcId = ApexPages.currentPage().getParameters().get('id');
objabc = new abc();
if(objabcId !=null && objabcId !=''){
objabc = [Select id,OwnerId,name from abc
where id=:ApexPages.currentPage().getParameters().get('id')];
}
if(objabc.id!=null){
sendEmail = true;
objtask= new task();
objtask.whatid=objabc.id;
objtask.RecordTypeId = [select Id,Name from RecordType where name='abcd' and SOBjectType='Task' limit 1].Id;
objtask.status = 'Completed';
objtask.type = 'Assigned';
objtask.OwnerID = UserInfo.getUserId();
objtask.Subject='Assignment';
}
}
public pagereference save() {
try {
if(objtask.subject!=null){
insert objtask;
update objabc;
if(sendEmail){
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail = true;
database.update(objabc,dlo);
}
}else{
Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,'Subject cannot be Null !!!'));
return null;
}
string abcobjurl = objabc.id;
abcobjurl = abcobjurl.substring(0,3);
PageReference orderPage = new PageReference('/' + abcobjurl);
return orderPage;
} catch (Exception e) {
system.debug('---inside Exception---'+e.getMessage());
system.debug('---inside Exception Line---'+e.getLineNumber());
Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,e.getMessage()));
return null;
}
}
}
Thanks in advance!
Please help me in writting test class for the below apex code:
public class xyz {
public abc objabc{get;set;}
public Boolean sendEmail {get; set;}
public Task objtask{get;set;}
public boolean isChecked{get;set;}
public xyz() {
String objabcId = ApexPages.currentPage().getParameters().get('id');
objabc = new abc();
if(objabcId !=null && objabcId !=''){
objabc = [Select id,OwnerId,name from abc
where id=:ApexPages.currentPage().getParameters().get('id')];
}
if(objabc.id!=null){
sendEmail = true;
objtask= new task();
objtask.whatid=objabc.id;
objtask.RecordTypeId = [select Id,Name from RecordType where name='abcd' and SOBjectType='Task' limit 1].Id;
objtask.status = 'Completed';
objtask.type = 'Assigned';
objtask.OwnerID = UserInfo.getUserId();
objtask.Subject='Assignment';
}
}
public pagereference save() {
try {
if(objtask.subject!=null){
insert objtask;
update objabc;
if(sendEmail){
Database.DMLOptions dlo = new Database.DMLOptions();
dlo.EmailHeader.triggerUserEmail = true;
database.update(objabc,dlo);
}
}else{
Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,'Subject cannot be Null !!!'));
return null;
}
string abcobjurl = objabc.id;
abcobjurl = abcobjurl.substring(0,3);
PageReference orderPage = new PageReference('/' + abcobjurl);
return orderPage;
} catch (Exception e) {
system.debug('---inside Exception---'+e.getMessage());
system.debug('---inside Exception Line---'+e.getLineNumber());
Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.Error,e.getMessage()));
return null;
}
}
}
Thanks in advance!
Try Below Test Class Please Mark It As Best Answer If It Helps
Thank You!
All Answers
Try Below Test Class Please Mark It As Best Answer If It Helps
Thank You!
The test class got worked. It gave code coverage 83%.
Thank you!!