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

i want test class for standard coontroller extesion class
public class Standardextensionclass {
public contact con;
public blob picture{get;set;}
private ApexPages.StandardController st;
public standardextensionclass(Apexpages.StandardController st){
this.con=(contact)st.getrecord();
}
public pagereference savewithImage(){
pagereference pr;
try{
insert con;
if(picture !=null){
Attachment at=new Attachment();
at.Body=picture;
at.name='Contact_' + con.id + '.jpg';
at.ParentId=con.id;
at.ContentType = 'application/jpg';
insert at;
con.Picture_path__c = '/servlet/servlet.FileDownload?file='+ at.id;
update con;
Pr = new PageReference('/'+con.id);
pr.setRedirect(true);
}
} catch(Exception e){
system.debug('Error Message==>'+e);
}
return pr;
}
}
public contact con;
public blob picture{get;set;}
private ApexPages.StandardController st;
public standardextensionclass(Apexpages.StandardController st){
this.con=(contact)st.getrecord();
}
public pagereference savewithImage(){
pagereference pr;
try{
insert con;
if(picture !=null){
Attachment at=new Attachment();
at.Body=picture;
at.name='Contact_' + con.id + '.jpg';
at.ParentId=con.id;
at.ContentType = 'application/jpg';
insert at;
con.Picture_path__c = '/servlet/servlet.FileDownload?file='+ at.id;
update con;
Pr = new PageReference('/'+con.id);
pr.setRedirect(true);
}
} catch(Exception e){
system.debug('Error Message==>'+e);
}
return pr;
}
}
Hi arun rupesh,
Please try this for your test class it covers your 94% code coverage.
Regards,
Suraj
All Answers
Let me inform if it helps you and kindly mark it best answer if it helps you so it make proper solution for others
thanks
sfdcmonkey.com
Hi arun rupesh,
Please try this for your test class it covers your 94% code coverage.
Regards,
Suraj
thank for your reply .your code run properly and it reaches 100% code coverage