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

Test Class for Blob
public PageReference sendEmail(){
//Creating the Contact
Contact tempContact = new Contact();
tempContact.LastName ='test';
tempContact.firstName = 'testmerfantz';
tempContact.email = 'noreply@salesforce.com';
tempContact.Account = [select id, name from Account limit 1];
Insert tempContact;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
emailTo=emailadd;
mail.setToAddresses(new String[] {emailTo});
PageReference ref = Page.PricelistFAEL;
Blob b = ref.getContentAsPDF();
Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
efa1.setFileName('Uplift Request.pdf');
efa1.setBody(b);
mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
mail.setTemplateId([select id, name from EmailTemplate where Name='Calculate Amount'].id);
mail.setTargetObjectId(tempContact.id);
mail.setSaveAsActivity(false);
mail.setWhatId(apexpages.currentpage().getparameters().get('id'));
try{
Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
if(resultMail[0].isSuccess()) {
response = 'Your Mail Successfully sent!';
flag=false;
}
else{
response = resultMail[0].getErrors().get(0).getMessage();
}
}catch(System.EmailException ex){
response = ex.getMessage();
}
// Delete the tempContact
Delete tempContact;
return null;
}
public PageReference SaveasPdf(){
system.debug('CurrentId>>>'+currentid);
Attachment newAttach = new Attachment();
PageReference ref = Page.PricelistFAEL;
Blob b = ref.getContentAsPDF();
newAttach.Name = 'Uplift Request';
newAttach.ParentId = currentid;
newAttach.Body = b;
Insert newAttach;
system.debug('CurrentId>>>'+currentid);
PageReference pageRef = new PageReference('/'+currentid);
pageRef.setRedirect(true);
return pageRef;
}
Hi, I want the test class for these two methods. If anyone know reply......
//Creating the Contact
Contact tempContact = new Contact();
tempContact.LastName ='test';
tempContact.firstName = 'testmerfantz';
tempContact.email = 'noreply@salesforce.com';
tempContact.Account = [select id, name from Account limit 1];
Insert tempContact;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
emailTo=emailadd;
mail.setToAddresses(new String[] {emailTo});
PageReference ref = Page.PricelistFAEL;
Blob b = ref.getContentAsPDF();
Messaging.EmailFileAttachment efa1 = new Messaging.EmailFileAttachment();
efa1.setFileName('Uplift Request.pdf');
efa1.setBody(b);
mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa1});
mail.setTemplateId([select id, name from EmailTemplate where Name='Calculate Amount'].id);
mail.setTargetObjectId(tempContact.id);
mail.setSaveAsActivity(false);
mail.setWhatId(apexpages.currentpage().getparameters().get('id'));
try{
Messaging.SendEmailResult[] resultMail = Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
if(resultMail[0].isSuccess()) {
response = 'Your Mail Successfully sent!';
flag=false;
}
else{
response = resultMail[0].getErrors().get(0).getMessage();
}
}catch(System.EmailException ex){
response = ex.getMessage();
}
// Delete the tempContact
Delete tempContact;
return null;
}
public PageReference SaveasPdf(){
system.debug('CurrentId>>>'+currentid);
Attachment newAttach = new Attachment();
PageReference ref = Page.PricelistFAEL;
Blob b = ref.getContentAsPDF();
newAttach.Name = 'Uplift Request';
newAttach.ParentId = currentid;
newAttach.Body = b;
Insert newAttach;
system.debug('CurrentId>>>'+currentid);
PageReference pageRef = new PageReference('/'+currentid);
pageRef.setRedirect(true);
return pageRef;
}
Hi, I want the test class for these two methods. If anyone know reply......
This will help you in any further test classes that you write. Link - https://developer.salesforce.com/page/An_Introduction_to_Apex_Code_Test_Methods
For Blobs, we generally check for not null asserts to verify it matched correctly
Do let me know if it helps
Thanks.
Ray
Can not use the getContent() or getContentAsPDF() in Apex test class.
One idea is posted on same
https://success.salesforce.com/ideaview?id=08730000000HzknAAC
Please modify your class method like below
Solution 1:-
Solution 2:-
http://blog.jeffdouglas.com/2010/07/14/attach-a-pdf-to-a-record-in-salesforce/
Please let us know if this will help you
Thanks
Amit Chaudhary