You need to sign in to do that
Don't have an account?
Test Class for outbound Email
HI ,
can any one help,
This is my Apex code
public with sharing class debitnoteemail
{
public final Debit_Note__c debit;
String[] toAddresses = new String[]{};
public debitnoteemail()
{
debit=[select id,Contact__c,Contact_Email__c from Debit_Note__c where id=:ApexPages.currentPage().getParameters().get('id')];
}
public Debit_Note__c getdebitnote()
{
return debit;
}
public string getemail
public PageReference sendemail()
{
PageReference ref=page.DemandNotePdf;
ref.getParameters().put('id',debit.id);
Blob body;
try
{
body=ref.getContent();
}
catch(VisualforceException e)
{
System.debug('Error');
}
Messaging.EmailFileAttachment Att=new Messaging.EmailFileAttachment();
Att.setFileName('DebitNote' + debit.Contact__c + '.pdf');
Att.setBody(body);
string val=email;
Messaging.SingleEmailMessage mail =new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[]{val});
mail.setSubject('PDF Email Demo');
mail.setHtmlBody('Here is the email you requested! Check the attachment!');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { att });
Messaging.sendEmail(new Messaging.SingleEmailMessage[]{mail});
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Email with PDF sent to '+val));
return null;
}
}
this is my test class:
@istest
public class senddebitnote
{
public static void debitnoteemail()
{
account acc=new account();
acc.name='test account';
acc.email__c='jabaraj.jaba@gmail.com';
insert acc;
Debit_Note__c deb=new Debit_Note__c();
deb.Account__c=acc.id;
deb.Contact_Email__c=acc.email__c;error: //Field is not writeable: Debit_Note__c.Contact_Email__c at line 13 column 9
insert deb;
PageReference ref=page.senddebitnote;
ref.getParameters().put('id',deb.id);
debitnoteemail da=new debitnoteemail();
test.starttest();
da.debit.id=deb.id;
// da.debit.Contact_Email__c=acc.email__c;
ref=da.sendemail();
test.stoptest();
}
}
Is deb.Contact_Email__c a formula field? It won't be writeable in that case.
Thanks Eric your right its formula field now i got the value from my Master Object ,thanks for your response....