You need to sign in to do that
Don't have an account?
Anjum Attar
SObject row was retrieved via SOQL without querying the requested field: Opportunity.Name Error is in expression '{!SendEmail}' in component <apex:commandButton> in page oppinvoicemail: Class.EmailOppInvoice.SendEmail: line 27, column 1
//@author : Anjum Attar
//Creation Date :
//Modification History :
public with sharing class EmailOppInvoice {
public Opportunity oppRecord{get;set;}
public String id{get;set;}
public String eSubject{get;set;}
public String eBody{get;set;}
//public Contact objcon = new Contact();
public EmailOppInvoice(ApexPages.StandardController controller) {
oppRecord = (Opportunity)controller.getRecord();
id = oppRecord.id;
oppRecord = [Select Id,Name,Email__c,Account.Id From Opportunity Where Id =: id];
eSubject ='';
eBody = '';
}
public EmailOppInvoice() {
}
public pageReference SendEmail() {
Messaging.singleEmailMessage email = new Messaging.singleEmailMessage();
PageReference pdfExample = new pagereference('/apex/OpportunityInvoice?id='+id);
pdfExample.setRedirect(true);
Blob content = pdfExample.getContent();
Messaging.emailFileAttachment fileAttachment = new Messaging.emailFileAttachment();
fileAttachment.setFileName('Invoice.pdf');
fileAttachment.setBody(content);
String[] eAddress = new List<String>();
try {
eAddress.add(oppRecord.Email__c);
email.setSubject(eSubject);
email.setPlainTextBody(eBody);
email.setToAddresses(eAddress);
email.setFileAttachments(new Messaging.EmailFileAttachment[] {fileAttachment});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
}
catch(Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Email Field of Account does not contain any value'));
}
return null;
}
}
//Creation Date :
//Modification History :
public with sharing class EmailOppInvoice {
public Opportunity oppRecord{get;set;}
public String id{get;set;}
public String eSubject{get;set;}
public String eBody{get;set;}
//public Contact objcon = new Contact();
public EmailOppInvoice(ApexPages.StandardController controller) {
oppRecord = (Opportunity)controller.getRecord();
id = oppRecord.id;
oppRecord = [Select Id,Name,Email__c,Account.Id From Opportunity Where Id =: id];
eSubject ='';
eBody = '';
}
public EmailOppInvoice() {
}
public pageReference SendEmail() {
Messaging.singleEmailMessage email = new Messaging.singleEmailMessage();
PageReference pdfExample = new pagereference('/apex/OpportunityInvoice?id='+id);
pdfExample.setRedirect(true);
Blob content = pdfExample.getContent();
Messaging.emailFileAttachment fileAttachment = new Messaging.emailFileAttachment();
fileAttachment.setFileName('Invoice.pdf');
fileAttachment.setBody(content);
String[] eAddress = new List<String>();
try {
eAddress.add(oppRecord.Email__c);
email.setSubject(eSubject);
email.setPlainTextBody(eBody);
email.setToAddresses(eAddress);
email.setFileAttachments(new Messaging.EmailFileAttachment[] {fileAttachment});
Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email});
return null;
}
catch(Exception e) {
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Email Field of Account does not contain any value'));
}
return null;
}
}
Please share your Visual force page. I am guessing the error is in commandbutton.
Kind regards,
CloudSavvyProg
<apex:page standardController="Opportunity" extensions="EmailOppInvoice">
<apex:form >
<apex:pageBlock title="Send Opportunity Invoice to Account">
<apex:pageMessages ></apex:pageMessages>
<apex:outputLabel for="Subject" value="Subject"> : <br/></apex:outputLabel>
<apex:inputText maxlength="80" id="Subject" size="80" value="{!eSubject}"/><br/><br/>
<apex:outputLabel for="Body" value="Body">:<br/></apex:outputLabel>
<apex:inputTextArea id="Body" rows="8" cols="80" value="{!eBody}"/><br/><br/>
<apex:commandButton action="{!SendEmail}" value="Send"/>
</apex:pageBlock>
</apex:form>
</apex:page>
the code you posted looks fine. Could you please post the code for OpportunityInvoice vf page?